### Question:
StubPlugin extends AbstractThreadedObservablePlugin { public void plugStubReader(String name, Boolean synchronous) { logger.info("Plugging a new reader with name " + name); Boolean exist = connectedStubNames.contains(name); if (!exist && synchronous) { readers.add(new StubReader(name)); } connectedStubNames.add(name); if (exist) { logger.error("Reader with name " + name + " was already plugged"); } } private  StubPlugin(); static StubPlugin getInstance(); @Override Map<String, String> getParameters(); @Override void setParameter(String key, String value); void plugStubReader(String name, Boolean synchronous); void plugStubReaders(Set<String> names, Boolean synchronous); void unplugStubReader(String name, Boolean synchronous); void unplugStubReaders(Set<String> names, Boolean synchronous);  }### Answer:
@Test public void testA_PlugOneReaderCount() throws InterruptedException, KeypleReaderException { final String READER_NAME = "testA_PlugOneReaderCount"; stubPlugin.plugStubReader(READER_NAME, true); Assert.assertEquals(1, stubPlugin.getReaders().size()); }
@Test public void testA_PlugOneReaderEvent() throws InterruptedException, KeypleReaderException { final CountDownLatch readerConnected = new CountDownLatch(1); final String READER_NAME = "testA_PlugReaders"; stubPlugin.addObserver(new ObservablePlugin.PluginObserver() { @Override public void update(PluginEvent event) { Assert.assertEquals(PluginEvent.EventType.READER_CONNECTED, event.getEventType()); Assert.assertEquals(1, event.getReaderNames().size()); Assert.assertEquals(READER_NAME, event.getReaderNames().first()); readerConnected.countDown(); } }); stubPlugin.plugStubReader(READER_NAME, false); readerConnected.await(2, TimeUnit.SECONDS); Assert.assertEquals(0, readerConnected.getCount()); }
@Test public void testC_PlugSameReaderTwice() throws InterruptedException, KeypleReaderException { final String READER_NAME = "testC_PlugSameReaderTwice"; stubPlugin.plugStubReader(READER_NAME, true); stubPlugin.plugStubReader(READER_NAME, true); logger.debug("Stubplugin readers size {} ", stubPlugin.getReaders().size()); Assert.assertEquals(1, stubPlugin.getReaders().size()); }