package com.github.dtschust.zork; import com.github.dtschust.zork.utils.CommandReader; import com.github.dtschust.zork.utils.IOWrapper; import org.junit.jupiter.api.Test; import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit; import static org.junit.jupiter.api.Assertions.assertEquals; class ZorkTest { /** Test the game interacting as a real player * WARNING: when looking at inventory (i) we are relying on the HashMap order, so the test may be unsafe */ @Test void testSampleGame() { String gameConfig = "sampleGame.xml"; String gameExecution = "RunThroughResults.txt"; CommandReader run = new CommandReader(gameExecution); IOWrapper io = new IOWrapper(true); new Thread(() -> { try { catchSystemExit(() -> Zork.runZork(gameConfig)); } catch (Exception ignored) {} }).start(); while(true){ switch(run.getInstructionType()) { case SEND: io.write(run.getInstruction()); break; case RECV: assertEquals(run.getInstruction(), io.read()); break; default: io.restore(); return; } } } }