Polish "Validate excluded autoconfiguration classes"
- Apply code formatting - Move configuration of excepted exception to immediately before line that will throw the exception - Use String.format with %n to produce platform-specific new lines See gh-7407
This commit is contained in:
		
							parent
							
								
									a9ffdca6f2
								
							
						
					
					
						commit
						65d0c07fd6
					
				| 
						 | 
					@ -57,6 +57,7 @@ import org.springframework.util.ClassUtils;
 | 
				
			||||||
 * @author Phillip Webb
 | 
					 * @author Phillip Webb
 | 
				
			||||||
 * @author Andy Wilkinson
 | 
					 * @author Andy Wilkinson
 | 
				
			||||||
 * @author Stephane Nicoll
 | 
					 * @author Stephane Nicoll
 | 
				
			||||||
 | 
					 * @author Madhura Bhave
 | 
				
			||||||
 * @since 1.3.0
 | 
					 * @since 1.3.0
 | 
				
			||||||
 * @see EnableAutoConfiguration
 | 
					 * @see EnableAutoConfiguration
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -164,13 +165,14 @@ public class EnableAutoConfigurationImportSelector
 | 
				
			||||||
		for (String exclusion : exclusions) {
 | 
							for (String exclusion : exclusions) {
 | 
				
			||||||
			if (ClassUtils.isPresent(exclusion, getClass().getClassLoader())
 | 
								if (ClassUtils.isPresent(exclusion, getClass().getClassLoader())
 | 
				
			||||||
					&& !configurations.contains(exclusion)) {
 | 
										&& !configurations.contains(exclusion)) {
 | 
				
			||||||
				message.append("\t- ").append(exclusion).append("\n");
 | 
									message.append("\t- ").append(exclusion).append(String.format("%n"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!message.toString().isEmpty()) {
 | 
							if (!message.toString().isEmpty()) {
 | 
				
			||||||
			throw new IllegalStateException(
 | 
								throw new IllegalStateException(String.format(
 | 
				
			||||||
					"The following classes could not be excluded because they are not auto-configuration classes:\n"
 | 
										"The following classes could not be excluded because they are"
 | 
				
			||||||
							+ message.toString());
 | 
												+ " not auto-configuration classes:%n%s",
 | 
				
			||||||
 | 
										message.toString()));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,7 +47,7 @@ import static org.mockito.BDDMockito.given;
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author Andy Wilkinson
 | 
					 * @author Andy Wilkinson
 | 
				
			||||||
 * @author Stephane Nicoll
 | 
					 * @author Stephane Nicoll
 | 
				
			||||||
 *
 | 
					 * @author Madhura Bhave
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class EnableAutoConfigurationImportSelectorTests {
 | 
					public class EnableAutoConfigurationImportSelectorTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -173,30 +173,31 @@ public class EnableAutoConfigurationImportSelectorTests {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void nonAutoConfigurationClassExclusionsShouldThrowException() throws Exception {
 | 
						public void nonAutoConfigurationClassExclusionsShouldThrowException()
 | 
				
			||||||
		this.expected.expect(IllegalStateException.class);
 | 
								throws Exception {
 | 
				
			||||||
		configureExclusions(new String[] { TestConfiguration.class.getName() },
 | 
							configureExclusions(new String[] { TestConfiguration.class.getName() },
 | 
				
			||||||
				new String[0], new String[0]);
 | 
									new String[0], new String[0]);
 | 
				
			||||||
 | 
							this.expected.expect(IllegalStateException.class);
 | 
				
			||||||
		this.importSelector.selectImports(this.annotationMetadata);
 | 
							this.importSelector.selectImports(this.annotationMetadata);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void nonAutoConfigurationClassNameExclusionsWhenPresentOnClassPathShouldThrowException()
 | 
						public void nonAutoConfigurationClassNameExclusionsWhenPresentOnClassPathShouldThrowException()
 | 
				
			||||||
			throws Exception {
 | 
								throws Exception {
 | 
				
			||||||
		this.expected.expect(IllegalStateException.class);
 | 
					 | 
				
			||||||
		configureExclusions(new String[0],
 | 
							configureExclusions(new String[0],
 | 
				
			||||||
				new String[] { "org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelectorTests.TestConfiguration" },
 | 
									new String[] {
 | 
				
			||||||
 | 
											"org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelectorTests.TestConfiguration" },
 | 
				
			||||||
				new String[0]);
 | 
									new String[0]);
 | 
				
			||||||
 | 
							this.expected.expect(IllegalStateException.class);
 | 
				
			||||||
		this.importSelector.selectImports(this.annotationMetadata);
 | 
							this.importSelector.selectImports(this.annotationMetadata);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void  nonAutoConfigurationPropertyExclusionsWhenPresentOnClassPathShouldThrowException()
 | 
						public void nonAutoConfigurationPropertyExclusionsWhenPresentOnClassPathShouldThrowException()
 | 
				
			||||||
			throws Exception {
 | 
								throws Exception {
 | 
				
			||||||
 | 
							configureExclusions(new String[0], new String[0], new String[] {
 | 
				
			||||||
 | 
									"org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelectorTests.TestConfiguration" });
 | 
				
			||||||
		this.expected.expect(IllegalStateException.class);
 | 
							this.expected.expect(IllegalStateException.class);
 | 
				
			||||||
		configureExclusions(new String[0],
 | 
					 | 
				
			||||||
				new String[0],
 | 
					 | 
				
			||||||
				new String[] { "org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelectorTests.TestConfiguration" });
 | 
					 | 
				
			||||||
		this.importSelector.selectImports(this.annotationMetadata);
 | 
							this.importSelector.selectImports(this.annotationMetadata);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue