Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,19 @@ void updateTable_performsNoUpdate_whenVersionIsAboveCurrent() throws SQLExceptio
verify(mockStatement).setString(1, "table_history");
verify(mockStatement, never()).executeUpdate();
}

@Test
@DisplayName("Given the stored version is negative, when updateTable is called, then no version-0 update is performed")
void updateTable_skipsVersionZeroUpdate_whenVersionIsNegative() throws SQLException {
when(mockConnection.prepareStatement(anyString())).thenReturn(mockStatement);
when(mockStatement.executeQuery()).thenReturn(mockResultSet);
when(mockResultSet.next()).thenReturn(true, false);
when(mockResultSet.getInt("table_version")).thenReturn(-1);

TableVersionHistoryDAO.updateTable(mockConnection);

verify(mockStatement).setString(1, "table_history");
verify(mockStatement, never()).executeUpdate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ void setPage_throwsForNegativePage() {

assertThrows(IllegalArgumentException.class, () -> gui.setPage(-1));
}

@Test
@DisplayName("Given max page is 0, when setPage to 1, then throws IllegalArgumentException")
void setPage_throwsForMaxPageBelowOne() {
TestPaginatedGui gui = new TestPaginatedGui(player, mockInventory, 0);
gui.getInventory();

assertThrows(IllegalArgumentException.class, () -> gui.setPage(1));
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,13 @@ void toString_addsParens_whenDoubleNegation() {
FunctionNode inner = new FunctionNode(c(5.0), 0);
assertEquals("-(-5)", new FunctionNode(inner, 0).toString());
}

// ── getValue default switch branch ────────────────────────────────────

@Test
@DisplayName("Given an out-of-range function index, when evaluating, then returns 0")
void getValue_returnsZero_whenFunctionIndexIsOutOfRange() {
FunctionNode node = new FunctionNode(c(5.0), FunctionNode.FUNCTIONS.length);
assertEquals(0.0, node.getValue(), DELTA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,24 @@ void toString_addsBrackets_whenDivisionWithDivisionLeft() {
OperatorNode node = new OperatorNode(left, c(4.0), '/');
assertEquals("(8/2)/4", node.toString());
}

// ── getValue default switch branch ────────────────────────────────────

@Test
@DisplayName("Given an unsupported operator character, when evaluating, then returns 0")
void getValue_returnsZero_whenOperatorIsUnsupported() {
OperatorNode node = new OperatorNode(c(3.0), c(4.0), '!');
assertEquals(0.0, node.getValue(), DELTA);
}

// ── needBrackets default switch branch ────────────────────────────────

@Test
@DisplayName("Given an unsupported operator with operator children, when converting to string, then adds brackets")
void toString_addsBrackets_whenOperatorIsUnsupported() {
OperatorNode left = new OperatorNode(c(1.0), c(2.0), '+');
OperatorNode right = new OperatorNode(c(3.0), c(4.0), '*');
OperatorNode node = new OperatorNode(left, right, '!');
assertEquals("(1+2)!(3*4)", node.toString());
}
}
Loading