OptionsImpl implements IOptions, IShutdownListener { protected void updateNotify (long sequence) { IServiceReference[] refs = null; try { if(aggregator != null && aggregator.getPlatformServices() != null){ refs = aggregator.getPlatformServices().getServiceReferences(IOptionsListener.class.getName(),"(name=" + registrationName + ")"); if (refs != null) { for (IServiceReference ref : refs) { IOptionsListener listener = (IOptionsListener)aggregator.getPlatformServices().getService(ref); if (listener != null) { try { listener.optionsUpdated(this, sequence); } catch (Throwable ignore) { } finally { aggregator.getPlatformServices().ungetService(ref); } } } } } } catch (PlatformServicesException e) { if (log.isLoggable(Level.SEVERE)) { log.log(Level.SEVERE, e.getMessage(), e); } } } OptionsImpl(boolean loadFromPropertiesFile, IAggregator aggregator); @Override boolean isVerifyDeps(); @Override boolean isDisableRequireListExpansion(); @Override boolean isDevelopmentMode(); @Override boolean isDebugMode(); @Override boolean isSourceMapsEnabled(); @Override boolean isDisableHasFiltering(); @Override boolean isDisableHasPluginBranching(); @Override boolean isDisableModuleNameIdEncoding(); @Override String getCacheBust(); @Override String getCacheDirectory(); @Override int getDeleteDelay(); @Override void setOption(String name, boolean value); @Override synchronized void setOption(String name, String value); @Override String getOption(String name); @Override Map<String, String> getOptionsMap(); @Override String getName(); @Override Map<String, String> getDefaultOptionsMap(); String getPropsFilename(); File getPropsFile(); @Override void shutdown(IAggregator aggregator);  }
@Test public void testUpdateNotify() throws Exception { final OptionsImpl options = new OptionsImpl(false, null); final int[] callCounts = new int[]{0, 0}; IAggregator mockAggregator = EasyMock.createNiceMock(IAggregator.class); IPlatformServices mockPlatformServices = EasyMock.createMock(IPlatformServices.class); IServiceReference[] mockServiceRefs = new IServiceReference[] { EasyMock.createMock(IServiceReference.class), EasyMock.createMock(IServiceReference.class) }; Whitebox.setInternalState(options, "aggregator", mockAggregator); Whitebox.setInternalState(options, "registrationName", "test"); EasyMock.expect(mockAggregator.getPlatformServices()).andReturn(mockPlatformServices).anyTimes(); EasyMock.expect(mockPlatformServices.getServiceReferences(IOptionsListener.class.getName(), "(name=test)")).andReturn(mockServiceRefs); EasyMock.expect(mockPlatformServices.getService(mockServiceRefs[0])).andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { return new IOptionsListener() { @Override public void optionsUpdated(IOptions updated, long sequence) { callCounts[0]++; Assert.assertSame(options, updated); Assert.assertEquals(1L, sequence); } }; } }); EasyMock.expect(mockPlatformServices.getService(mockServiceRefs[1])).andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { return new IOptionsListener() { @Override public void optionsUpdated(IOptions updated, long sequence) { callCounts[1]++; Assert.assertSame(options, updated); Assert.assertEquals(1L, sequence); throw new RuntimeException(); } }; } }); EasyMock.expect(mockPlatformServices.ungetService(mockServiceRefs[0])).andReturn(true); EasyMock.expect(mockPlatformServices.ungetService(mockServiceRefs[1])).andReturn(true); EasyMock.replay(mockAggregator, mockPlatformServices, mockServiceRefs[0], mockServiceRefs[1]); options.updateNotify(1L); EasyMock.verify(mockAggregator, mockPlatformServices, mockServiceRefs[0], mockServiceRefs[1]); Assert.assertEquals(1, callCounts[0]); Assert.assertEquals(1, callCounts[1]); }