ApplicationContextFactory { public ClassPathXmlApplicationContext getClassPathXmlApplicationContext(final String path) { ClassPathXmlApplicationContext applicationContext = applicationContexts.get(path); if (applicationContext == null) { applicationContext = new ClassPathXmlApplicationContext(path); applicationContexts.put(path, applicationContext); } return applicationContext; } ApplicationContextFactory(); static ApplicationContextFactory getInstance(); ClassPathXmlApplicationContext getClassPathXmlApplicationContext(final String path); ClassPathXmlApplicationContext getApplicationContext(final String springAppContextPath);  }
@Test public void testGetClassPathXmlApplicationContextShouldCreateNewAppContext() { ClassPathXmlApplicationContext actual = underTest.getClassPathXmlApplicationContext(SPRING_APP_CONTEXT_PATH); Assert.assertTrue(actual.containsBean("test")); }
@Test public void testGetClassPathXmlApplicationContextShouldReturnTheSameAppContextForACertainPath() { ClassPathXmlApplicationContext expected = new ClassPathXmlApplicationContext(SPRING_APP_CONTEXT_PATH); Map<String, ClassPathXmlApplicationContext> appContexts = new HashMap<>(); appContexts.put(SPRING_APP_CONTEXT_PATH, expected); Whitebox.setInternalState(underTest, "applicationContexts", appContexts); ClassPathXmlApplicationContext actual = underTest.getClassPathXmlApplicationContext(SPRING_APP_CONTEXT_PATH); Assert.assertEquals(actual, expected); }