@Test public void equalsWithNullArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), null, null, null, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), null, null, null, loader); assertEquals(mergedConfig1, mergedConfig2); }
@Test public void equalsWithSameDuplicateProfiles() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "catbert", "dogbert", "catbert", "dogbert", "catbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader); assertEquals(mergedConfig1, mergedConfig2); }
@Test public void equalsWithEmptyArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); assertEquals(mergedConfig1, mergedConfig2); }
@Test public void equalsWithSameProfilesReversed() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "dogbert", "catbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader); assertNotEquals(mergedConfig1, mergedConfig2); }
/** * @since 4.3 */ @Test public void equalsWithSameContextCustomizers() { Set<ContextCustomizer> customizers = Collections.singleton(mock(ContextCustomizer.class)); MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers, loader, null, null); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers, loader, null, null); assertEquals(mergedConfig1, mergedConfig2); }
@Test public void equalsWithSameLocations() { String[] locations = new String[] { "foo", "bar}" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), locations, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), locations, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); assertEquals(mergedConfig1, mergedConfig2); }
@Test public void equalsWithSameProfiles() { String[] activeProfiles = new String[] { "catbert", "dogbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader); assertEquals(mergedConfig1, mergedConfig2); }
@Test public void equalsWithDifferentLocations() { String[] locations1 = new String[] { "foo", "bar}" }; String[] locations2 = new String[] { "baz", "quux}" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), locations1, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), locations2, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); assertNotEquals(mergedConfig1, mergedConfig2); assertNotEquals(mergedConfig2, mergedConfig1); }
@Test public void equalsWithDifferentProfiles() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "X", "Y" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader); assertNotEquals(mergedConfig1, mergedConfig2); assertNotEquals(mergedConfig2, mergedConfig1); }
@Test public void equalsWithDifferentConfigClasses() { Class<?>[] classes1 = new Class<?>[] { String.class, Integer.class }; Class<?>[] classes2 = new Class<?>[] { Boolean.class, Number.class }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, classes1, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, classes2, EMPTY_STRING_ARRAY, loader); assertNotEquals(mergedConfig1, mergedConfig2); assertNotEquals(mergedConfig2, mergedConfig1); }
@Test public void hashCodeWithNullArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), null, null, null, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), null, null, null, loader); assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode()); }
@Test public void hashCodeWithEmptyArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode()); }
@Test public void hashCodeWithDifferentConfigClasses() { Class<?>[] classes1 = new Class<?>[] { String.class, Integer.class }; Class<?>[] classes2 = new Class<?>[] { Boolean.class, Number.class }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, classes1, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, classes2, EMPTY_STRING_ARRAY, loader); assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode()); }
@Test public void hashCodeWithNulls() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(null, null, null, null, null); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(null, null, null, null, null); assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode()); }
@Test public void loadContextWithConfigurationClass() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClassTestCase.class, EMPTY_STRING_ARRAY, new Class<?>[] {ConfigClassTestCase.Config.class}, EMPTY_STRING_ARRAY, loader); assertApplicationContextLoadsAndContainsFooString(mergedConfig); }
@Test public void configMustNotContainAnnotatedClasses() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(containsString("does not support annotated classes")); GenericXmlContextLoader loader = new GenericXmlContextLoader(); MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, new Class<?>[] { getClass() }, EMPTY_STRING_ARRAY, loader); loader.loadContext(mergedConfig); }
/** * @since 4.0.4 */ @Test public void configMustNotContainLocations() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(containsString("does not support resource locations")); MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), new String[] { "config.xml" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, contextLoader); contextLoader.loadContext(mergedConfig); }
@Test public void configMustNotContainAnnotatedClasses() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(containsString("does not support annotated classes")); GenericPropertiesContextLoader loader = new GenericPropertiesContextLoader(); MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, new Class<?>[] { getClass() }, EMPTY_STRING_ARRAY, loader); loader.loadContext(mergedConfig); }
@Test public void loadContextWithoutLocationsAndConfigurationClasses() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(startsWith("Neither")); expectedException.expectMessage(containsString("was able to load an ApplicationContext from")); MergedContextConfiguration mergedConfig = new MergedContextConfiguration( getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); loader.loadContext(mergedConfig); }
@Test public void equalsBasics() { MergedContextConfiguration mergedConfig = new MergedContextConfiguration(null, null, null, null, null); assertEquals(mergedConfig, mergedConfig); assertNotEquals(mergedConfig, null); assertNotEquals(mergedConfig, 1); }