/** * Determine if this {@code ContextConfigurationAttributes} instance has * class-based resources. * @return {@code true} if the {@link #getClasses() classes} array is not empty * @see #hasResources() * @see #hasLocations() */ public boolean hasClasses() { return (getClasses().length > 0); }
smartContextLoader.processContextConfiguration(configAttributes); locations.addAll(0, Arrays.asList(configAttributes.getLocations())); classes.addAll(0, Arrays.asList(configAttributes.getClasses()));
@Test public void processContextConfigurationWithConfigurationClass() { Class<?>[] classes = new Class<?>[] {getClass()}; ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( getClass(), EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertArrayEquals(classes, configAttributes.getClasses()); assertEmpty(configAttributes.getLocations()); }
@Test public void processContextConfigurationWithLocation() { String[] locations = new String[] {"classpath:/foo.xml"}; ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertArrayEquals(locations, configAttributes.getLocations()); assertEmpty(configAttributes.getClasses()); }
@Test public void processContextConfigurationWithDefaultXmlConfigGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertEquals(1, configAttributes.getLocations().length); assertEmpty(configAttributes.getClasses()); }
@Test public void processContextConfigurationWithDefaultConfigurationClassGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertEquals(1, configAttributes.getClasses().length); assertEmpty(configAttributes.getLocations()); }
void assertAttributes(ContextConfigurationAttributes attributes, Class<?> expectedDeclaringClass, String[] expectedLocations, Class<?>[] expectedClasses, Class<? extends ContextLoader> expectedContextLoaderClass, boolean expectedInheritLocations) { assertEquals("declaring class", expectedDeclaringClass, attributes.getDeclaringClass()); assertArrayEquals("locations", expectedLocations, attributes.getLocations()); assertArrayEquals("classes", expectedClasses, attributes.getClasses()); assertEquals("inherit locations", expectedInheritLocations, attributes.isInheritLocations()); assertEquals("context loader", expectedContextLoaderClass, attributes.getContextLoaderClass()); }
/** * Determine if this {@code ContextConfigurationAttributes} instance has * class-based resources. * @return {@code true} if the {@link #getClasses() classes} array is not empty * @see #hasResources() * @see #hasLocations() */ public boolean hasClasses() { return (getClasses().length > 0); }
/** * Determine if this {@code ContextConfigurationAttributes} instance has * class-based resources. * @return {@code true} if the {@link #getClasses() classes} array is not empty * @see #hasResources() * @see #hasLocations() */ public boolean hasClasses() { return !ObjectUtils.isEmpty(getClasses()); }
private void addConfigAttributesClasses( ContextConfigurationAttributes configAttributes, Class<?>[] classes) { List<Class<?>> combined = new ArrayList<>(); combined.addAll(Arrays.asList(classes)); if (configAttributes.getClasses() != null) { combined.addAll(Arrays.asList(configAttributes.getClasses())); } configAttributes.setClasses(ClassUtils.toClassArray(combined)); }
private boolean isFromConfiguration(MergedContextConfiguration candidateConfig, ContextConfiguration configuration) { ContextConfigurationAttributes attributes = new ContextConfigurationAttributes( candidateConfig.getTestClass(), configuration); Set<Class<?>> configurationClasses = new HashSet<>( Arrays.asList(attributes.getClasses())); for (Class<?> candidate : candidateConfig.getClasses()) { if (configurationClasses.contains(candidate)) { return true; } } return false; }
@Override public void processContextConfiguration( ContextConfigurationAttributes configAttributes ) { Class<?>[] classes = configAttributes.getClasses(); if( classes.length == 0 ) { // Allow empty loaders, in this case everything should be mocked configAttributes.setClasses( new Class<?>[]{Object.class} ); } super.processContextConfiguration( configAttributes ); }
smartContextLoader.processContextConfiguration(configAttributes); locations.addAll(0, Arrays.asList(configAttributes.getLocations())); classes.addAll(0, Arrays.asList(configAttributes.getClasses()));
smartContextLoader.processContextConfiguration(configAttributes); locations.addAll(0, Arrays.asList(configAttributes.getLocations())); classes.addAll(0, Arrays.asList(configAttributes.getClasses()));