@Test public void testParseCorrect() { try { testInstruction.parse("turn " + Rotation.LEFT); testInstruction.parse("girar " + Rotation.LEFT); } catch (WrongInstructionFormatException e) { fail("ERROR: A correct instruction throws an exception"); } }
@Test public void testWronginstruction() { try { testInstruction.parse("gira left"); fail("ERROR: A wrong instruction (gira left) does not throw an exception"); } catch (WrongInstructionFormatException e) { // If we catch the exception then the parsing is correct } }
@Test public void testWrongParameter() { try { testInstruction.parse("turn izda"); fail("ERROR: A turn instruction with a wrong parameter does not throw an exception"); } catch (WrongInstructionFormatException e) { // If we catch the exception then the parsing is correct } }
@Test public void testTurnCorrect() { try { testInstruction = testInstruction.parse("turn right"); testInstruction.configureContext(testEngine, testNavModule, null); testInstruction.execute(); assertEquals( "ERROR: The robot is not heading to the correct direction after a turn instruction", Direction.EAST, testNavModule.getCurrentHeading()); testInstruction = testInstruction.parse("turn left"); testInstruction.configureContext(testEngine, testNavModule, null); testInstruction.execute(); assertEquals( "ERROR: The robot is not heading to the correct direction after a turn instruction", Direction.NORTH, testNavModule.getCurrentHeading()); } catch (WrongInstructionFormatException e) { fail("ERROR: parse throws an exception with a correct instruction"); } catch (InstructionExecutionException e) { fail("ERROR: execute throws an exception when the action is correct"); } }