Skip to content

Commit

Permalink
AuditBoard tests
Browse files Browse the repository at this point in the history
- also removing some unneeded imports
  • Loading branch information
umbernhard committed Dec 3, 2024
1 parent 351e3e3 commit 9b2ba65
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import java.nio.charset.StandardCharsets;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import au.org.democracydevelopers.corla.endpoint.AbstractAllIrvEndpoint;
import au.org.democracydevelopers.corla.model.ContestType;
import au.org.democracydevelopers.corla.model.GenerateAssertionsSummary;
import au.org.democracydevelopers.corla.model.IRVComparisonAudit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package us.freeandfair.corla.model;

import com.github.tomakehurst.wiremock.core.Admin;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
import us.freeandfair.corla.persistence.Persistence;
import us.freeandfair.corla.query.AdministratorQueries;
import us.freeandfair.corla.util.TestClassWithDatabase;

import java.time.Clock;
import java.time.Instant;

import static org.testng.Assert.assertNotEquals;
import static org.testng.AssertJUnit.*;
import static us.freeandfair.corla.util.EqualsHashcodeHelper.nullableHashCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package us.freeandfair.corla.model;

import org.testng.annotations.Test;
import us.freeandfair.corla.util.TestClassWithDatabase;

import java.lang.reflect.Array;
import java.time.Instant;

import java.util.ArrayList;

import static org.testng.AssertJUnit.*;
import static us.freeandfair.corla.util.EqualsHashcodeHelper.nullableHashCode;

public class AuditBoardTest extends TestClassWithDatabase {

@Test
public static void testGettersAndSetters () {

AuditBoard defaultAB = new AuditBoard();
assertEquals(new ArrayList<Elector>(), defaultAB.members());
assertNull(defaultAB.signInTime());
assertNull(defaultAB.signOutTime());

ArrayList<Elector> electors = new ArrayList<>();

electors.add(new Elector("firstname", "lastname", "party"));

// TODO: do we want a stopped clock here too?
Instant sign_in_time = Instant.now();

AuditBoard ab = new AuditBoard(electors, sign_in_time);

assertEquals(electors, ab.members());

assertEquals(sign_in_time, ab.signInTime());

Instant sign_out_time = Instant.now();

ab.setSignOutTime(sign_out_time);
assertEquals(sign_out_time, ab.signOutTime());

String expectedToString = "AuditBoard [members=" + electors + ", sign_in_time=" +
sign_in_time + ", sign_out_time=" + sign_out_time + "]";

assertEquals(expectedToString, ab.toString());

assertEquals(nullableHashCode(sign_in_time), ab.hashCode());

assertFalse(ab.equals("Not an auditboard"));
ArrayList<Elector> otherElectors = new ArrayList<>();
otherElectors.add(new Elector("otherfirstname", "otherlastname", "otherparty"));

AuditBoard otherAB = new AuditBoard(otherElectors, sign_in_time);

assertFalse(ab.equals(otherAB));
assertTrue(ab.equals(ab));

}
}

0 comments on commit 9b2ba65

Please sign in to comment.