OdsFileWriterAdapter implements NamedOdsFileWriter { public synchronized void flushAdaptee() throws IOException { OdsAsyncFlusher flusher = this.flushers.poll(); this.logger.fine("Retrieve first flusher: " + flusher); if (flusher == null) { this.notifyAll(); return; } while (flusher != null) { this.adaptee.update(flusher); if (flusher.isEnd()) { this.stopped = true; this.notifyAll(); return; } flusher = this.flushers.poll(); this.logger.fine("Retrieve next flusher: " + flusher); } this.notifyAll(); } OdsFileWriterAdapter(final Logger logger, final NamedOdsFileWriter adaptee,
                         final Queue<OdsAsyncFlusher> flushers); static OdsFileWriterAdapter create(final Logger logger,
                                              final NamedOdsFileWriter adaptee); @Override void close(); @Override NamedOdsDocument document(); @Override synchronized void save(); @Override synchronized void update(final OdsAsyncFlusher flusher); synchronized void flushAdaptee(); synchronized boolean isNotStopped(); synchronized void waitForData();  }
@Test public void testFlushAdapteeWithEmptyQueue() throws Exception { PowerMock.resetAll(); this.logger.fine("Retrieve first flusher: null"); PowerMock.replayAll(); this.wa.flushAdaptee(); PowerMock.verifyAll(); }
@Test public void testFlushAdaptee() throws Exception { final OdsFileWriterAdapter wal = this.wa; final FinalizeFlusher ff = PowerMock.createMock(FinalizeFlusher.class); this.flushers.add(this.f); this.flushers.add(ff); final Thread t = new Thread() { @Override public void run() { try { Thread.sleep(100); } catch (final InterruptedException e) { Assert.fail(); } synchronized (wal) { wal.notify(); } } }; PowerMock.resetAll(); this.logger .fine("Retrieve first flusher: EasyMock for interface com.github.jferard.fastods" + ".OdsAsyncFlusher"); this.logger .fine("Retrieve next flusher: EasyMock for class com.github.jferard.fastods" + ".FinalizeFlusher"); EasyMock.expect(this.f.isEnd()).andReturn(false); EasyMock.expect(ff.isEnd()).andReturn(true); this.w.update(this.f); this.w.update(ff); PowerMock.replayAll(); t.start(); this.wa.flushAdaptee(); PowerMock.verifyAll(); }
@Test public void testInterruptFlushAdatee() throws Exception { final OdsFileWriterAdapter wal = this.wa; final Logger l = this.logger; final Thread t = new Thread() { @Override public void run() { try { PowerMock.resetAll(); l.fine("Retrieve first flusher: null"); PowerMock.replayAll(); wal.flushAdaptee(); PowerMock.verifyAll(); } catch (final RuntimeException e) { return; } catch (final IOException e) { Assert.fail(); } } }; t.start(); Thread.sleep(100); t.join(); }