Exemple #1
0
def assertProperty(property, expectation, i=0):
    assertAgainst = expectation[property]
    if property == "code":
        assertAgainst = [
            line[line.find(')') + 1:] for line in expectation[property][1:]
        ]
    assert testinggame._find_java_tests(
        expectation['code'])[i][property] == assertAgainst
Exemple #2
0
def testParserToParseCodeInTestInClassExample():
    expectedCode = {
        'code': [
            ")    @Test", ")    public void testInClassExample() {",
            ")        Assert.assertEquals(0, 0);", ")",
            ")        Assert.assertEquals(0, 0);", ")",
            ")        Assert.assertEquals(0, 0);", ")    }"
        ]
    }
    property = 'code'
    parsedExpectedCode = [
        line[line.find(')') + 1:] for line in expectedCode[property][1:]
    ]
    assert testinggame._find_java_tests(
        testInClassExample['code'])[0][property] == parsedExpectedCode
Exemple #3
0
def testParserToParseCodeInSmallSetupExample():
    expectedCode = {
        "code": [
            ")    @Test", ")    public void testSetupExample() {",
            ")        Square[][] grid = new Square[6][4];",
            ")        for (int x = 0; x < grid.length; x++) {",
            ")            for (int y = 0; y < grid[x].length; y++) {",
            ")                grid[x][y] = new BasicSquare();",
            ")            }", ")        }",
            ")        board = new Board(grid);",
            ")        Assert.assertEquals(0, 0);", ")",
            ")        Assert.assertEquals(0, 0);", ")",
            ")        Assert.assertEquals(0, 0);", ")    }"
        ]
    }
    property = 'code'
    parsedExpectedCode = [
        line[line.find(')') + 1:] for line in expectedCode[property][1:]
    ]
    assert testinggame._find_java_tests(
        smallSetupExample['code'])[0][property] == parsedExpectedCode
Exemple #4
0
def testParserToParseCodeInSmallReferenceExample():
    expectedCode = {
        "code": [
            ")    @Test", ")    void win() {",
            ")        final int randomPoints = 42;",
            ")        when(level.isAnyPlayerAlive()).thenReturn(true);",
            ")        when(level.remainingPellets()).thenReturn(randomPoints);",
            ")", ")        game.start();", ")",
            ")        verify(level).start();",
            ")        verify(level).addObserver(game);",
            ")        assertThat(game.isInProgress()).isTrue();",
            ")        game.levelWon();",
            ")        assertThat(game.isInProgress()).isFalse();", ")    }"
        ]
    }
    property = 'code'
    parsedExpectedCode = [
        line[line.find(')') + 1:] for line in expectedCode[property][1:]
    ]
    assert testinggame._find_java_tests(
        smallReferenceExample['code'])[1][property] == parsedExpectedCode
Exemple #5
0
def testParserToParseCodeInBigReferenceExample():
    expectedCode = {
        "code": [
            ")    @Test", ")    void stop() {",
            ")        MockitoAnnotations.initMocks(this);",
            ")        game = new SinglePlayerGame(player, level);",
            ")        final int randomPoints = 42;",
            ")        when(level.isAnyPlayerAlive()).thenReturn(true);",
            ")        when(level.remainingPellets()).thenReturn(randomPoints);",
            ")", ")        game.start();", ")",
            ")        verify(level).start();",
            ")        verify(level).addObserver(game);",
            ")        assertThat(game.isInProgress()).isTrue();",
            ")        game.stop();",
            ")        assertThat(game.isInProgress()).isFalse();",
            ")        verify(level).stop();", ")    }"
        ]
    }
    property = 'code'
    parsedExpectedCode = [
        line[line.find(')') + 1:] for line in expectedCode[property][1:]
    ]
    assert testinggame._find_java_tests(
        bigReferenceExample['code'])[1][property] == parsedExpectedCode