@Test public void testExtensions() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext); assertEquals(0, GeoServerExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]); expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class)) .andReturn(new String[] {"testKey", "fakeKey"}); expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]); expect(appContext.getBean("testKey")).andReturn(this); // note I'm testing null is a valid value. If that's not the case, it // should be reflected in the code, but I'm writing the test after the // code so that's what it does expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes(); expect(appContext.getBean("fakeKey")).andReturn(null); replay(appContext); List<GeoServerExtensionsTest> extensions = GeoServerExtensions.extensions(GeoServerExtensionsTest.class); assertNotNull(extensions); assertEquals(2, extensions.size()); assertTrue(extensions.contains(this)); assertTrue(extensions.contains(null)); assertEquals(3, GeoServerExtensions.extensionsCache.size()); assertTrue(GeoServerExtensions.extensionsCache.containsKey(GeoServerExtensionsTest.class)); assertNotNull(GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class)); assertEquals( 2, GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class).length); verify(appContext); }
@Test public void testSetApplicationContext() { ApplicationContext appContext1 = createMock(ApplicationContext.class); ApplicationContext appContext2 = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext1); GeoServerExtensions.extensionsCache.put( GeoServerExtensionsTest.class, new String[] {"fake"}); assertSame(appContext1, GeoServerExtensions.context); gse.setApplicationContext(appContext2); assertSame(appContext2, GeoServerExtensions.context); assertEquals(0, GeoServerExtensions.extensionsCache.size()); }
/** * Returns the number of elements in this collection. */ public int size() { return SoftValueHashMap.this.size(); }
@Test public void testExtensions() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext); assertEquals(0, GeoServerExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]); expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class)) .andReturn(new String[] {"testKey", "fakeKey"}); expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]); expect(appContext.getBean("testKey")).andReturn(this); // note I'm testing null is a valid value. If that's not the case, it // should be reflected in the code, but I'm writing the test after the // code so that's what it does expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes(); expect(appContext.getBean("fakeKey")).andReturn(null); replay(appContext); List<GeoServerExtensionsTest> extensions = GeoServerExtensions.extensions(GeoServerExtensionsTest.class); assertNotNull(extensions); assertEquals(2, extensions.size()); assertTrue(extensions.contains(this)); assertTrue(extensions.contains(null)); assertEquals(3, GeoServerExtensions.extensionsCache.size()); assertTrue(GeoServerExtensions.extensionsCache.containsKey(GeoServerExtensionsTest.class)); assertNotNull(GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class)); assertEquals( 2, GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class).length); verify(appContext); }
@Test public void testSetApplicationContext() { ApplicationContext appContext1 = createMock(ApplicationContext.class); ApplicationContext appContext2 = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext1); GeoServerExtensions.extensionsCache.put( GeoServerExtensionsTest.class, new String[] {"fake"}); assertSame(appContext1, GeoServerExtensions.context); gse.setApplicationContext(appContext2); assertSame(appContext2, GeoServerExtensions.context); assertEquals(0, GeoServerExtensions.extensionsCache.size()); }