Skip to content

Commit

Permalink
test&update[DbWrapper]: add test for exporting user with too long Str…
Browse files Browse the repository at this point in the history
…ing and handle exception throwing in DonationsTest
  • Loading branch information
Lucy Ciara Herud-Thomassen authored and Lucy Ciara Herud-Thomassen committed Apr 21, 2026
1 parent d6016d5 commit 35f4d49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ void init() {
this.nullList.add(nullRow);

this.db.connect();
this.db.exportUsers(users);
try {
this.db.exportUsers(users);
} catch (Exception e) {
// This exception won't happen
}
}

private static boolean donationEquals(Object[] array1, Object[] array2) {
Expand Down
27 changes: 25 additions & 2 deletions src/test/java/edu/group5/app/model/wrapper/DbWrapperUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -20,12 +21,14 @@ public class DbWrapperUserTest {
private Object[] cutoffJoh;
private Object[] freakyBill;
private Object[] repeatingJoeJoe;
private Object[] bigWilly;
private List<Object[]> users;
private List<Object[]> users2;
private List<Object[]> users3;
private List<Object[]> repeatedUsers;
private List<Object[]> wrongFormatUsers;
private List<Object[]> wrongDatatypeUsers;
private List<Object[]> tooBigUsers;
private List<Object[]> nullList;

private DbWrapper db;
Expand Down Expand Up @@ -60,6 +63,12 @@ void init() {
this.wrongDatatypeUsers = new ArrayList<Object[]>();
this.wrongDatatypeUsers.add(freakyBill);

this.bigWilly = new Object[] {
6, "Customer", "Big", "Willy", "bigdwilly@waaaaaytoolargemail.com", "passssssssssssword"
};
this.tooBigUsers = new ArrayList<Object[]>();
this.tooBigUsers.add(this.bigWilly);

Object[] nullRow = new Object[] {null, null, null, null, null, null};
this.nullList = new ArrayList<Object[]>();
this.nullList.add(nullRow);
Expand Down Expand Up @@ -122,7 +131,7 @@ public void wronglyDatatypedUsersThrowsExpectedException() {
public void addingSameUserTwiceThrowsExpectedException() {
assertTrue(this.db.connect());
assertTrue(this.db.importUsers().size() == 0);
assertEquals(1, this.db.exportUsers(this.users));
assertDoesNotThrow(() -> assertEquals(1, this.db.exportUsers(this.users)));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
this.db.exportUsers(this.users);
});
Expand All @@ -135,7 +144,7 @@ public void addingSameUserTwiceThrowsExpectedException() {
public void addingSameUserTwiceThrowsExpectedException2() {
assertTrue(this.db.connect());
assertTrue(this.db.importUsers().size() == 0);
assertEquals(2, this.db.exportUsers(this.users2));
assertDoesNotThrow(() -> assertEquals(2, this.db.exportUsers(this.users2)));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
this.db.exportUsers(this.users);
});
Expand Down Expand Up @@ -179,4 +188,18 @@ public void addingUserListWithNullInRowThrowsExpectedException() {
assertTrue(this.db.disconnect());
assertEquals("One or more rows in data contains null values", exception.getMessage());
}

@Test
public void exportTooLongNameThrowsSQLException() {
assertTrue(this.db.connect());
assertTrue(this.db.importUsers().size() == 0);
SQLException exception = assertThrows(SQLException.class, () -> {
this.db.exportUsers(this.tooBigUsers);
});
assertEquals(
"An unexpected SQL exception has occurred. " +
"This might be caused by inserting an item that is too large.",
exception.getMessage()
);
}
}

0 comments on commit 35f4d49

Please sign in to comment.