@Test public void testShouldProcessAllRows() throws Exception { tables = parse("[rule for][calculator]\n" + "[a][b][sum?][division?]\n" + "[6][2][8][3]\n" + "[10][5][15][2]"); interpreter.interpret(spec()); assertAnnotatedRight(tables.at(0, 2, 2)); assertAnnotatedRight(tables.at(0, 2, 3)); assertAnnotatedRight(tables.at(0, 3, 2)); assertAnnotatedRight(tables.at(0, 3, 3)); }
@Test public void testCheckSpecialActionColorsFirstKeywordCellOnException() throws Exception { doThrow(new Exception("Command failed")).when(fixture).commandThrowingException(); tables = Tables.parse("[do with][mock]\n" + "[check][commandThrowingException][value]"); interpreter.interpret(document()); verify(fixture).commandThrowingException(); assertAnnotatedException(tables.at(0, 1, 1)); assertNotAnnotated(tables.at(0, 1, 2)); }
@Test public void testCheckSpecialActionExpectsValueOfLastCellAndColorsLastCell() throws Exception { when(fixture.thatValueOfIs("balance")).thenReturn("100", "150"); tables = Tables.parse("[workflow][mock]\n" + "[check][that value of][balance][is][100]\n" + "[check][that value of][balance][is][120]"); interpreter.interpret(document()); verify(fixture, times(2)).thatValueOfIs("balance"); assertAnnotatedRight(tables.at(0, 1, 4)); assertAnnotatedWrongWithDetails(tables.at(0, 2, 4)); }
@Test public void testThatMissingRowsAreAnnotatedMissing() { tables = Tables.parse("[set of][values]\n" + "[intValue]\n" + "[1]\n" + "[2]\n" + "[3]\n" + "[4]"); interpreter = new SetOfInterpreter(new PlainOldFixture(new Integer[] { 1, 2, 4 })); interpreter.interpret(document()); assertAnnotatedRight(tables.at(0, 2, 0)); assertAnnotatedRight(tables.at(0, 3, 0)); assertAnnotatedMissing(tables.at(0, 4, 0)); assertAnnotatedRight(tables.at(0, 5, 0)); }
@Test public void testThatFirstCellIsAnnotatedRightIfMethodExecutesNormallyAndReturnsTrue() { doReturn(true).when(fixture).performCheck("argument1"); Tables tables = tablesFor("[action][mock]\n" + "[performCheck][argument1]"); interpreter.interpret(specificationFor(tables)); verify(fixture).performCheck("argument1"); assertAnnotatedRight(tables.at(0, 1, 0)); assertNotAnnotated(tables.at(0, 1, 1)); }
public String[] parameters() { Action action = Action.parse(row.actionCells(tables.at(0, 0))); return action.arguments(); } }
public String[] parameters() { Action action = Action.parse(row.actionCells(tables.at(0, 0))); return action.arguments(); } }
@Test public void testInterpreterCollectsTestExecutionStatistics() throws Exception { tables = Tables.parse("[list of][values]\n" + "[a][b][c]\n" + "[1][2][4]"); interpreter = new ListOfInterpreter(fixtureThatReturnsABC()); interpreter.interpret(document()); assertAnnotatedRight(tables.at(0, 2, 0)); assertAnnotatedRight(tables.at(0, 2, 1)); assertAnnotatedWrongWithDetails(tables.at(0, 2, 2)); }
@Test public void testShouldTestColumnWhenHeaderEndsWithQuestionMark() throws Exception { tables = parse("[rule for][calculator]\n" + "[sum?][product?]\n" + "[5] [7]"); calculator.a = 3; calculator.b = 2; interpreter.interpret(spec()); assertAnnotatedRight(tables.at(0, 2, 0)); assertAnnotatedWrongWithDetails(tables.at(0, 2, 1)); }
@Test public void testSkipsTableWhenInterpreterCannotBeFound() { Tables table = parse("[MissingInterpreter]"); Interpreter interpreter = selector.selectInterpreter(table); assertThat(interpreter, is(instanceOf(SkipInterpreter.class))); Assertions.assertAnnotatedException(table.at(0, 0, 0)); }
@Test public void testActionsCanReturnAFixtureToInterpretRestOfTable() throws Exception { doReturn(Object.class).when(fixture).commandTakingNoParameter(); tables = Tables.parse("[do with][mock]\n" + "[" + RightInterpreter.class.getName() + "][commandTakingNoParameter]\n" + "[actionOnReturnedFixture]\n" + "[actionOnReturnedFixture]"); interpreter.interpret(document()); verify(fixture).commandTakingNoParameter(); Example rows = tables.at(0, 1); assertAnnotatedRight(rows.at(1, 0)); assertAnnotatedRight(rows.at(2, 0)); }
@Test public void testThatCellWithMethodThrowingAnExceptionIsConsideredAsMissing() throws Exception { tables = Tables.parse("[set of][values]\n" + "[ex]\n" + "[1]\n" + "[2]\n" + "[3]"); interpreter = new SetOfInterpreter(fixtureThatReturnsFoosAndBars()); FakeSpecification document = document(); interpreter.interpret(document); assertTrue(document.stats().indicatesFailure()); assertAnnotatedMissing(tables.at(0, 2, 0)); assertAnnotatedMissing(tables.at(0, 3, 0)); assertAnnotatedMissing(tables.at(0, 4, 0)); }
@Test public void testThatCellWithResultIsAdded() { tables = parse("[setup][dummy Fixture]\n" + "[a][b]\n" + "[5][3]\n" + "[2][3]"); interpreter.interpret(document()); Assertions.assertAnnotatedEntered(tables.at(0, 2, 2)); }
@Test public void testComplainsIfInterpreterCannotBeLoaded() { tables = parse("[NotAnInterpreter]\n" + "[1][2][3]"); execute(document()); Assertions.assertAnnotatedException(tables.at(0, 0, 0)); }
@Test public void testFixtureReturnsFewerRowsUsingStopOnFirstFailure() throws Exception { LivingDoc.setStopOnFirstFailure(true); tables = Tables.parse("[list of][values]\n" + "[bar]\n" + "[1]\n" + "[2]\n" + "[3]\n" + "[4]"); interpreter = new ListOfInterpreter(fixtureThatReturnsFoosAndBars()); FakeSpecification document = document(); interpreter.interpret(document); assertTrue(document.stats().indicatesFailure()); assertAnnotatedMissing(tables.at(0, 5, 0)); assertAnnotatedStopped(tables.at(0, 5, 1)); }
@Test public void testThatFixtureWithoutAProperCollectionQueryHasAnnotatedCellToExceptionAndStopWhenStopOnFirstFailure() { LivingDoc.setStopOnFirstFailure(true); tables = Tables.parse("[list of][values]\n" + "[bar]\n" + "[1]"); interpreter = new ListOfInterpreter(new DefaultFixture(new FixtureThatHasNoCollection())); FakeSpecification document = document(); interpreter.interpret(document); assertTrue(document.stats().indicatesFailure()); assertAnnotatedException(tables.at(0, 1, 0)); assertAnnotatedStopped(tables.at(0, 1, 1)); }
@Test public void testThatCellContainingBadValueIsAnnotatedStoppedWhenOptionsIsStopOnFirstFailure() { LivingDoc.setStopOnFirstFailure(true); tables = parse("[decision table][calculator]\n" + "[a][b]\n" + "[fail][3]"); FakeSpecification document = spec(); interpreter.interpret(document); assertTrue(document.stats().hasFailed()); Assertions.assertAnnotatedStopped(tables.at(0, 2, 2)); }
@Test public void testThatCellContainingBadValueIsAnnotatedStoppedWhenOptionsIsStopOnFirstFailure() { LivingDoc.setStopOnFirstFailure(true); tables = parse("[setup][dummy Fixture]\n" + "[a][b]\n" + "[fail][3]\n" + "[2][3]"); FakeSpecification document = document(); interpreter.interpret(document); assertTrue(document.stats().hasFailed()); Assertions.assertAnnotatedStopped(tables.at(0, 2, 2)); }
@Test public void testThatFixtureWithoutAProperCollectionQueryHasAnnotatedCellToException() { tables = Tables.parse("[set of][values]\n" + "[bytes]\n" + "[]"); interpreter = new SetOfInterpreter(new DefaultFixture("")); FakeSpecification document = document(); interpreter.interpret(document); assertTrue(document.stats().indicatesFailure()); assertAnnotatedException(tables.at(0, 1, 0)); }