Skip to content

Commit

Permalink
fix[DBWrapper]: Fix exporting of Donations to successfully export whe…
Browse files Browse the repository at this point in the history
…n closing the application
  • Loading branch information
Fredrik Marjoni committed Mar 20, 2026
1 parent 4444322 commit 8676d9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/edu/group5/app/control/wrapper/DbWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ public List<Object[]> importUsers() {

public int exportUsers(List<Object[]> data) {
this.importUsers();

if (data == null) {
throw new IllegalArgumentException("data can't be null");
}
if (data.isEmpty()) {
return 0;
}
if (data.get(0).length != 6) {
throw new IllegalArgumentException("data's arrays must have a length of 6");
}
Expand Down Expand Up @@ -184,10 +187,13 @@ private List<Object[]> importDonations(int user_id, boolean all) {

public int exportDonations(List<Object[]> data) {
this.fetchAllDonations();

if (data == null) {
throw new IllegalArgumentException("data can't be null");
}
if (data.isEmpty()) {
return 0;
}
if (data.get(0).length != 6) {
throw new IllegalArgumentException("data's arrays must have a length of 6");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,12 @@ public void addingDonationListWithNullInRowThrowsExpectedException() {
assertTrue(this.db.disconnect());
assertEquals("One or more rows in data contains null values", exception.getMessage());
}

@Test
public void dataIsEmptyAfterExportingAndImportingEmptyList() {
assertTrue(this.db.importDonations((int) this.users.get(0)[0]).size() == 0);
assertEquals(0, this.db.exportDonations(new ArrayList<Object[]>()));
assertTrue(this.db.importDonations((int) this.users.get(0)[0]).size() == 0);
assertTrue(this.db.disconnect());
}
}

0 comments on commit 8676d9b

Please sign in to comment.