diff --git a/src/test/java/edu/group5/app/model/wrapper/DbWrapperDonationsTest.java b/src/test/java/edu/group5/app/model/wrapper/DbWrapperDonationsTest.java index f9cc8ff..289b803 100644 --- a/src/test/java/edu/group5/app/model/wrapper/DbWrapperDonationsTest.java +++ b/src/test/java/edu/group5/app/model/wrapper/DbWrapperDonationsTest.java @@ -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) { diff --git a/src/test/java/edu/group5/app/model/wrapper/DbWrapperUserTest.java b/src/test/java/edu/group5/app/model/wrapper/DbWrapperUserTest.java index 00107de..e8621d8 100644 --- a/src/test/java/edu/group5/app/model/wrapper/DbWrapperUserTest.java +++ b/src/test/java/edu/group5/app/model/wrapper/DbWrapperUserTest.java @@ -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; @@ -20,12 +21,14 @@ public class DbWrapperUserTest { private Object[] cutoffJoh; private Object[] freakyBill; private Object[] repeatingJoeJoe; + private Object[] bigWilly; private List users; private List users2; private List users3; private List repeatedUsers; private List wrongFormatUsers; private List wrongDatatypeUsers; + private List tooBigUsers; private List nullList; private DbWrapper db; @@ -60,6 +63,12 @@ void init() { this.wrongDatatypeUsers = new ArrayList(); this.wrongDatatypeUsers.add(freakyBill); + this.bigWilly = new Object[] { + 6, "Customer", "Big", "Willy", "bigdwilly@waaaaaytoolargemail.com", "passssssssssssword" + }; + this.tooBigUsers = new ArrayList(); + this.tooBigUsers.add(this.bigWilly); + Object[] nullRow = new Object[] {null, null, null, null, null, null}; this.nullList = new ArrayList(); this.nullList.add(nullRow); @@ -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); }); @@ -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); }); @@ -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() + ); + } }