Increase test coverage

Fixed an intermittent deadlock in MainTest:
FlushListener could receive more than the expected number of flushes
before the VirtualTerminalInteractor was given control. So by setting
the flush count to zero in waitForFlushes(), flushes could be lost. Now
it only reduces the number of flushes by the expected number.
This commit is contained in:
Mike Cifelli 2017-03-24 11:53:33 -04:00
parent a8620307c9
commit 2de2e3947a
4 changed files with 16 additions and 10 deletions

View File

@ -17,7 +17,7 @@ public class LispInterpreterFixture {
private static LispInterpreter interpreter = null;
public static void buildInterpreter() {
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {};
builder.setOutput(new PrintStream(outputStream));
builder.setErrorOutput(new PrintStream(outputStream));
builder.setNotInteractive();

View File

@ -41,9 +41,12 @@ public class MainTest {
latch = new CountDownLatch(1);
new Thread(() -> {
LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration());
main.runInteractive();
latch.countDown();
try {
LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration());
main.runInteractive();
} finally {
latch.countDown();
}
}).start();
return terminal;
@ -121,8 +124,11 @@ public class MainTest {
}
@Test
public void defaultConstructorCoverage() {
new LispMain();
public void runMain() {
LispMain.main(new String[] { "test/main/test-files/file.lisp" });
assertEquals("", getSystemErrLog());
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
}
}

View File

@ -12,12 +12,12 @@ public class FlushListener implements VirtualTerminalListener {
this.flushCount = 0;
}
public int getFlushCount() {
public synchronized int getFlushCount() {
return flushCount;
}
public void resetFlushCount() {
flushCount = 0;
public synchronized void reduceFlushCount(int reduction) {
flushCount -= reduction;
}
@Override

View File

@ -110,7 +110,7 @@ public class VirtualTerminalInteractor {
while (flushListener.getFlushCount() < flushCount)
flushListener.wait();
flushListener.resetFlushCount();
flushListener.reduceFlushCount(flushCount);
}
} catch (InterruptedException ignored) {}
}