From c59c1f40c1908bb30f73c0b84a801377bd925346 Mon Sep 17 00:00:00 2001 From: vteague Date: Tue, 23 Jul 2024 21:28:12 +1000 Subject: [PATCH 1/2] Comment improvements based on @michelleblom's review. --- .../model/GenerateAssertionsSummary.java | 38 +++- .../model/vote/IRVBallotInterpretation.java | 19 +- .../GenerateAssertionsSummaryQueries.java | 10 +- .../corla/csv/DominionCVRExportParser.java | 6 +- .../freeandfair/corla/report/ReportRows.java | 2 +- .../csv/DominionCVRExportParserTests.java | 172 +++++++++--------- .../corla/endpoint/GetAssertionsTests.java | 2 +- ...GenerateAssertionsSummaryQueriesTests.java | 150 +++++++++++++++ ...RankedBallotInterpretationReportTests.java | 26 +-- 9 files changed, 308 insertions(+), 117 deletions(-) create mode 100644 server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java diff --git a/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/GenerateAssertionsSummary.java b/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/GenerateAssertionsSummary.java index 08afe85b..6b3a39d1 100644 --- a/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/GenerateAssertionsSummary.java +++ b/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/GenerateAssertionsSummary.java @@ -63,13 +63,13 @@ public class GenerateAssertionsSummary { * Name of the contest. */ @Column(name = "contest_name", unique = true, updatable = false, nullable = false) - public String contestName; + private String contestName; /** * Name of the winner of the contest, as determined by raire-java. */ @Column(name = "winner", updatable = false, nullable = false) - public String winner; + private String winner; /** * An error (matching one of the RaireServiceErrors.RaireErrorCodes), if there was one. Errors @@ -78,7 +78,7 @@ public class GenerateAssertionsSummary { * continue. */ @Column(name = "error", updatable = false, nullable = false) - public String error; + private String error; /** * A warning, if there was one, or emptystring if none. Warnings (e.g. TIME_OUT_TRIMMING_ASSERTIONS) @@ -86,17 +86,45 @@ public class GenerateAssertionsSummary { * time allowed might be beneficial. */ @Column(name = "warning", updatable = false, nullable = false) - public String warning; + private String warning; /** * The message associated with the error, for example the names of the tied winners. */ @Column(name = "message", updatable = false, nullable = false) - public String message; + private String message; /** * Default no-args constructor (required for persistence). */ public GenerateAssertionsSummary() { } + + /** + * @return the winner. + */ + public String getWinner() { + return winner; + } + + /** + * @return the error, or emptystring if there is none. + */ + public String getError() { + return error; + } + + /** + * @return a warning, or emptystring if there is none. + */ + public String getWarning() { + return warning; + } + + /** + * @return the message associated with the error, or emptystring if there is none. + */ + public String getMessage() { + return message; + } } \ No newline at end of file diff --git a/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/vote/IRVBallotInterpretation.java b/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/vote/IRVBallotInterpretation.java index a9c450a6..437e4cca 100644 --- a/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/vote/IRVBallotInterpretation.java +++ b/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/model/vote/IRVBallotInterpretation.java @@ -21,7 +21,7 @@ */ @Entity @Table(name = "irv_ballot_interpretation") -public class IRVBallotInterpretation implements PersistentEntity, Serializable { +public class IRVBallotInterpretation implements PersistentEntity { /** * ID for interpretation record (for persistence). @@ -87,16 +87,19 @@ public IRVBallotInterpretation() { /** * Create a record of an IRV vote interpretation for a given contest and a given ballot - * (identified by the CVR ID). + * (identified by the CVR ID). This works for any IRV vote, but is expected to be used only + * for invalid IRV votes. * @param contest the Contest * @param recordType the type, expected to be either UPLOADED, AUDITOR_ENTERED, or REAUDITED. - * @param cvrNumber the cvr Number, which appears in the csv file (not to be confused with the cvr_id, which the - * database makes). + * @param cvrNumber the cvr Number, which appears in the csv file (not to be confused with + * the cvr_id, which the database makes). * @param imprintedId the imprinted ID, i.e. tabulator_id-batch_id-record_id. * @param rawChoices the (invalid) raw IRV choices, e.g. [Bob(1),Alice(3),Chuan(4)]. * @param orderedChoices the way colorado-rla interpreted the raw choices, as an order list of names. */ - public IRVBallotInterpretation(Contest contest, CastVoteRecord.RecordType recordType, int cvrNumber, String imprintedId, List rawChoices, List orderedChoices) { + public IRVBallotInterpretation(final Contest contest, final CastVoteRecord.RecordType recordType, + int cvrNumber, final String imprintedId, final List rawChoices, + final List orderedChoices) { this.contest = contest; this.recordType = recordType; this.cvrNumber = cvrNumber; @@ -106,10 +109,10 @@ public IRVBallotInterpretation(Contest contest, CastVoteRecord.RecordType record } /** - * Output contents as a String appropriate for a log message. + * Output details of the stored IRV vote interpretation as a String appropriate for a log message. * @return the data with headers incorporated. */ - public String logMessage(String cvrNumberHeader, String imprintedIDHeader) { + public String logMessage(final String cvrNumberHeader, final String imprintedIDHeader) { return String.join(", ", (List.of( "County " + contest.county().name(), "Contest " + contest.name(), @@ -132,7 +135,7 @@ public Long id() { * {@inheritDoc} */ @Override - public void setID(Long the_id) { + public void setID(final Long the_id) { id = the_id; } diff --git a/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueries.java b/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueries.java index 8a21b69e..6cb71ca0 100644 --- a/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueries.java +++ b/server/eclipse-project/src/main/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueries.java @@ -35,7 +35,7 @@ /** * Database queries relating to the retrieval of Assertion Generation Summaries from the - * database. It contains a method that executes a query to retrieval all GenerateAssertionsSummaries + * database. It contains a method that executes a query to retrieve all GenerateAssertionsSummaries * belonging to a specific contest, identified by name. * Also includes a shortcut function to get the winner, which inserts UNKNOWN_WINNER if either the * record is absent, or the winner is blank. @@ -54,9 +54,9 @@ public class GenerateAssertionsSummaryQueries { * @param contestName the name of the contest. */ public static String matchingWinner(final String contestName) { - Optional optSummary = matching(contestName); - if(optSummary.isPresent() && !optSummary.get().winner.isBlank()) { - return optSummary.get().winner; + final Optional optSummary = matching(contestName); + if(optSummary.isPresent() && !optSummary.get().getWinner().isBlank()) { + return optSummary.get().getWinner(); } else { return UNKNOWN_WINNER; } @@ -80,7 +80,7 @@ public static Optional matching(final String contestN + " where ca.contestName = :contestName", GenerateAssertionsSummary.class); q.setParameter("contestName", contestName); - List result = q.getResultList(); + final List result = q.getResultList(); LOGGER.debug(String.format("%s %d summary results retrieved for contest %s.", prefix, result.size(), contestName)); if(result.isEmpty()) { diff --git a/server/eclipse-project/src/main/java/us/freeandfair/corla/csv/DominionCVRExportParser.java b/server/eclipse-project/src/main/java/us/freeandfair/corla/csv/DominionCVRExportParser.java index a3d61dce..a9ee624c 100644 --- a/server/eclipse-project/src/main/java/us/freeandfair/corla/csv/DominionCVRExportParser.java +++ b/server/eclipse-project/src/main/java/us/freeandfair/corla/csv/DominionCVRExportParser.java @@ -670,14 +670,14 @@ private CastVoteRecord extractCVR(final CSVRecord the_line) { // If it is IRV, convert it into an ordered list of names (without parentheses), then // store. final IRVChoices irvVotes = new IRVChoices(votes); - List orderedChoices = irvVotes.getValidIntentAsOrderedList(); + final List orderedChoices = irvVotes.getValidIntentAsOrderedList(); if(!irvVotes.isValid()) { // IRV preferences were invalid. Store a record of the raw votes for debugging/record- // keeping purposes, but use the valid interpretation as the choices in the audit. - IRVBallotInterpretation irvInterpretation = new IRVBallotInterpretation(co, + final IRVBallotInterpretation irvInterpretation = new IRVBallotInterpretation(co, RecordType.UPLOADED, cvr_id, imprinted_id, votes, orderedChoices); Persistence.save(irvInterpretation); - String msg = "Interpretation of invalid IRV choices."; + final String msg = "Interpretation of invalid IRV choices."; LOGGER.warn(String.format("%s %s %s.", prefix, msg, irvInterpretation.logMessage(CVR_NUMBER_HEADER, IMPRINTED_ID_HEADER))); } diff --git a/server/eclipse-project/src/main/java/us/freeandfair/corla/report/ReportRows.java b/server/eclipse-project/src/main/java/us/freeandfair/corla/report/ReportRows.java index 23f1003e..e7b35036 100644 --- a/server/eclipse-project/src/main/java/us/freeandfair/corla/report/ReportRows.java +++ b/server/eclipse-project/src/main/java/us/freeandfair/corla/report/ReportRows.java @@ -359,7 +359,7 @@ public static BigDecimal percentage(final BigDecimal num) { } /** - * for each contest(per row), show all the variables that are interesting or + * For each contest (per row), show all the variables that are interesting or * needed to perform the risk limit calculation * This checks whether the contest is IRV and makes two modifications: * 1. it takes the winner from the GenerateAssertionsSummary table, rather than the ComparisonAudit, diff --git a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/csv/DominionCVRExportParserTests.java b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/csv/DominionCVRExportParserTests.java index 6170f994..b148bc74 100644 --- a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/csv/DominionCVRExportParserTests.java +++ b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/csv/DominionCVRExportParserTests.java @@ -116,21 +116,22 @@ public static void afterAll() { @Transactional public void parseThreeCandidatesTenVotesSucceeds() throws IOException { testUtils.log(LOGGER, "parseThreeCandidatesTenVotesSucceeds"); - Path path = Paths.get(TINY_CSV_PATH + "ThreeCandidatesTenVotes.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(TINY_CSV_PATH + "ThreeCandidatesTenVotes.csv"); + final Reader reader = Files.newBufferedReader(path); final List ABC = List.of("Alice","Bob","Chuan"); final List ACB = List.of("Alice","Chuan","Bob"); final List BAC = List.of("Bob","Alice","Chuan"); final List CAB = List.of("Chuan","Alice","Bob"); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Saguache"), blank, true); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, + fromString("Saguache"), blank, true); assertTrue(parser.parse().success); // There should be one contest, the one we just read in. - List contests = forCounties(Set.of(fromString("Saguache"))); + final List contests = forCounties(Set.of(fromString("Saguache"))); assertEquals(1, contests.size()); - Contest contest = contests.get(0); + final Contest contest = contests.get(0); // Check basic data assertEquals(contest.name(), "TinyExample1"); @@ -152,8 +153,8 @@ public void parseThreeCandidatesTenVotesSucceeds() throws IOException { BAC, CAB, CAB, CAB); - List cvrs = getMatching(fromString("Saguache").id(), CastVoteRecord.RecordType.UPLOADED) - .map(cvr -> cvr.contestInfoForContest(contest)).toList(); + final List cvrs = getMatching(fromString("Saguache").id(), + CastVoteRecord.RecordType.UPLOADED).map(cvr -> cvr.contestInfoForContest(contest)).toList(); assertEquals(10, cvrs.size()); for(int i=0 ; i < expectedChoices.size() ; i++) { assertEquals(cvrs.get(i).choices(), expectedChoices.get(i)); @@ -169,17 +170,17 @@ public void parseThreeCandidatesTenVotesSucceeds() throws IOException { @Transactional public void parseGuideToRaireExample3() throws IOException { testUtils.log(LOGGER, "parseGuideToRaireExample3"); - Path path = Paths.get(TINY_CSV_PATH + "GuideToRAIREExample3.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(TINY_CSV_PATH + "GuideToRAIREExample3.csv"); + final Reader reader = Files.newBufferedReader(path); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Montezuma"), - blank, true); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, + fromString("Montezuma"), blank, true); assertTrue(parser.parse().success); // There should be one contest, the one we just read in. - List contests = forCounties(Set.of(fromString("Montezuma"))); + final List contests = forCounties(Set.of(fromString("Montezuma"))); assertEquals(1, contests.size()); - Contest contest = contests.get(0); + final Contest contest = contests.get(0); // Check basic data assertEquals(contest.name(), "Example3"); @@ -192,8 +193,8 @@ public void parseGuideToRaireExample3() throws IOException { assertEquals(contest.winnersAllowed().intValue(), 1); // There are 225 votes. Spot-check some of them. - List cvrs = getMatching(fromString("Montezuma").id(), CastVoteRecord.RecordType.UPLOADED) - .map(cvr -> cvr.contestInfoForContest(contest)).toList(); + final List cvrs = getMatching(fromString("Montezuma").id(), + CastVoteRecord.RecordType.UPLOADED).map(cvr -> cvr.contestInfoForContest(contest)).toList(); assertEquals(225, cvrs.size()); assertEquals(List.of("C", "D"), cvrs.get(0).choices()); assertEquals(List.of("C", "D"), cvrs.get(44).choices()); @@ -217,16 +218,17 @@ public void parseGuideToRaireExample3() throws IOException { @Transactional public void parseThreeCandidatesTenInvalidVotesSucceeds() throws IOException { testUtils.log(LOGGER, "parseThreeCandidatesTenInvalidVotesSucceeds"); - Path path = Paths.get(TINY_CSV_PATH + "ThreeCandidatesTenInvalidVotes.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(TINY_CSV_PATH + "ThreeCandidatesTenInvalidVotes.csv"); + final Reader reader = Files.newBufferedReader(path); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Gilpin"), blank, true); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, + fromString("Gilpin"), blank, true); assertTrue(parser.parse().success); // There should be one contest, the one we just read in. - List contests = forCounties(Set.of(fromString("Gilpin"))); + final List contests = forCounties(Set.of(fromString("Gilpin"))); assertEquals(1, contests.size()); - Contest contest = contests.get(0); + final Contest contest = contests.get(0); // Check basic data assertEquals(contest.name(), "TinyInvalidExample1"); @@ -239,8 +241,8 @@ public void parseThreeCandidatesTenInvalidVotesSucceeds() throws IOException { assertEquals(contest.winnersAllowed().intValue(), 1); // There are 10 votes, with respective valid interpretations as below: - List cvrs = getMatching(fromString("Gilpin").id(), CastVoteRecord.RecordType.UPLOADED) - .map(cvr -> cvr.contestInfoForContest(contest)).toList(); + final List cvrs = getMatching(fromString("Gilpin").id(), + CastVoteRecord.RecordType.UPLOADED).map(cvr -> cvr.contestInfoForContest(contest)).toList(); assertEquals(10, cvrs.size()); // Raw: "Alice(1),Alice(2),Bob(2),Chuan(3) @@ -275,228 +277,228 @@ public void parseThreeCandidatesTenInvalidVotesSucceeds() throws IOException { @Transactional public void parseBoulder23Succeeds() throws IOException { testUtils.log(LOGGER, "parseBoulder23Succeeds"); - Path path = Paths.get(BOULDER_CSV_PATH + "Boulder-2023-Coordinated-CVR-Redactions-removed.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(BOULDER_CSV_PATH + "Boulder-2023-Coordinated-CVR-Redactions-removed.csv"); + final Reader reader = Files.newBufferedReader(path); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Boulder"), + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Boulder"), blank, true); assertTrue(parser.parse().success); // There should be 38 contests. Check their metadata. - List contests = forCounties(Set.of(fromString("Boulder"))); + final List contests = forCounties(Set.of(fromString("Boulder"))); assertEquals(38, contests.size()); - Contest boulderMayoral = contests.get(0); + final Contest boulderMayoral = contests.get(0); assertEquals(boulderMayoral.name(), "City of Boulder Mayoral Candidates"); assertEquals((int) boulderMayoral.votesAllowed(), 4); assertEquals((int) boulderMayoral.winnersAllowed(), 1); - Contest boulderCouncil = contests.get(1); + final Contest boulderCouncil = contests.get(1); assertEquals(boulderCouncil.name(), "City of Boulder Council Candidates"); assertEquals((int) boulderCouncil.votesAllowed(), 4); assertEquals((int) boulderCouncil.winnersAllowed(), 4); - Contest lafayetteCouncil = contests.get(2); + final Contest lafayetteCouncil = contests.get(2); assertEquals(lafayetteCouncil.name(), "City of Lafayette City Council Candidates"); assertEquals((int) lafayetteCouncil.votesAllowed(), 4); assertEquals((int) lafayetteCouncil.winnersAllowed(), 4); - Contest longmontMayor = contests.get(3); + final Contest longmontMayor = contests.get(3); assertEquals(longmontMayor.name(),"City of Longmont - Mayor"); assertEquals((int) longmontMayor.votesAllowed(), 1); assertEquals((int) longmontMayor.winnersAllowed(), 1); - Contest longmontCouncillorAtLarge = contests.get(4); + final Contest longmontCouncillorAtLarge = contests.get(4); assertEquals(longmontCouncillorAtLarge.name(), "City of Longmont - City Council Member At-Large"); assertEquals((int) longmontCouncillorAtLarge.votesAllowed(), 1); assertEquals((int) longmontCouncillorAtLarge.winnersAllowed(), 1); - Contest longmontCouncillorWard1 = contests.get(5); + final Contest longmontCouncillorWard1 = contests.get(5); assertEquals(longmontCouncillorWard1.name(),"City of Longmont - Council Member Ward 1"); assertEquals((int) longmontCouncillorWard1.votesAllowed(), 1); assertEquals((int) longmontCouncillorWard1.winnersAllowed(), 1); - Contest longmontCouncillorWard3 = contests.get(6); + final Contest longmontCouncillorWard3 = contests.get(6); assertEquals(longmontCouncillorWard3.name(),"City of Longmont - Council Member Ward 3"); assertEquals((int) longmontCouncillorWard3.votesAllowed(), 1); assertEquals((int) longmontCouncillorWard3.winnersAllowed(), 1); - Contest louisvilleMayor = contests.get(7); + final Contest louisvilleMayor = contests.get(7); assertEquals(louisvilleMayor.name(),"City of Louisville Mayor At-Large (4 Year Term)"); assertEquals((int) louisvilleMayor.votesAllowed(), 1); assertEquals((int) louisvilleMayor.winnersAllowed(), 1); - Contest louisvilleCouncilWard1 = contests.get(8); + final Contest louisvilleCouncilWard1 = contests.get(8); assertEquals(louisvilleCouncilWard1.name(), "City of Louisville City Council Ward 1 (4-year term)"); assertEquals((int) louisvilleCouncilWard1.votesAllowed(), 1); assertEquals((int) louisvilleCouncilWard1.winnersAllowed(), 1); - Contest louisvilleCouncilWard2 = contests.get(9); + final Contest louisvilleCouncilWard2 = contests.get(9); assertEquals(louisvilleCouncilWard2.name(), "City of Louisville City Council Ward 2 (4-year term)"); assertEquals((int) louisvilleCouncilWard2.votesAllowed(), 1); assertEquals((int) louisvilleCouncilWard2.winnersAllowed(), 1); - Contest louisvilleCouncilWard3 = contests.get(10); + final Contest louisvilleCouncilWard3 = contests.get(10); assertEquals( louisvilleCouncilWard3.name(), "City of Louisville City Council Ward 3"); assertEquals((int) louisvilleCouncilWard3.votesAllowed(), 2); assertEquals((int) louisvilleCouncilWard3.winnersAllowed(), 2); - Contest boulderValleySchoolDirectorA = contests.get(11); + final Contest boulderValleySchoolDirectorA = contests.get(11); assertEquals( boulderValleySchoolDirectorA.name(), "Boulder Valley School District RE-2 Director District A (4 Years)"); assertEquals((int) boulderValleySchoolDirectorA.votesAllowed(), 1); assertEquals((int) boulderValleySchoolDirectorA.winnersAllowed(), 1); - Contest boulderValleySchoolDirectorC = contests.get(12); + final Contest boulderValleySchoolDirectorC = contests.get(12); assertEquals(boulderValleySchoolDirectorC.name(), "Boulder Valley School District RE-2 Director District C (4 Years)"); assertEquals((int) boulderValleySchoolDirectorC.votesAllowed(), 1); assertEquals((int) boulderValleySchoolDirectorC.winnersAllowed(), 1); - Contest boulderValleySchoolDirectorD = contests.get(13); + final Contest boulderValleySchoolDirectorD = contests.get(13); assertEquals(boulderValleySchoolDirectorD.name(), "Boulder Valley School District RE-2 Director District D (4 Years)"); assertEquals((int) boulderValleySchoolDirectorD.votesAllowed(), 1); assertEquals((int) boulderValleySchoolDirectorD.winnersAllowed(), 1); - Contest boulderValleySchoolDirectorG = contests.get(14); + final Contest boulderValleySchoolDirectorG = contests.get(14); assertEquals(boulderValleySchoolDirectorG.name(), "Boulder Valley School District RE-2 Director District G (4 Years)"); assertEquals((int) boulderValleySchoolDirectorG.votesAllowed(), 1); assertEquals((int) boulderValleySchoolDirectorG.winnersAllowed(), 1); - Contest estesParkSchoolDirectorAtLarge = contests.get(15); + final Contest estesParkSchoolDirectorAtLarge = contests.get(15); assertEquals(estesParkSchoolDirectorAtLarge.name(), "Estes Park School District R-3 School Board Director At Large (4 Year)"); assertEquals((int) estesParkSchoolDirectorAtLarge.votesAllowed(), 2); assertEquals((int) estesParkSchoolDirectorAtLarge.winnersAllowed(), 2); - Contest thompsonSchoolDirectorA = contests.get(16); + final Contest thompsonSchoolDirectorA = contests.get(16); assertEquals(thompsonSchoolDirectorA.name(), "Thompson R2-J School District Board of Education Director District A (4 Year Term)"); assertEquals((int) thompsonSchoolDirectorA.votesAllowed(), 1); assertEquals((int) thompsonSchoolDirectorA.winnersAllowed(), 1); - Contest thompsonSchoolDirectorC = contests.get(17); + final Contest thompsonSchoolDirectorC = contests.get(17); assertEquals(thompsonSchoolDirectorC.name(), "Thompson R2-J School District Board of Education Director District C (4 Year Term)"); assertEquals((int) thompsonSchoolDirectorC.votesAllowed(), 1); assertEquals((int) thompsonSchoolDirectorC.winnersAllowed(), 1); - Contest thompsonSchoolDirectorD = contests.get(18); + final Contest thompsonSchoolDirectorD = contests.get(18); assertEquals( thompsonSchoolDirectorD.name(), "Thompson R2-J School District Board of Education Director District D (4 Year Term)"); assertEquals((int) thompsonSchoolDirectorD.votesAllowed(), 1); assertEquals((int) thompsonSchoolDirectorD.winnersAllowed(), 1); - Contest thompsonSchoolDirectorG = contests.get(19); + final Contest thompsonSchoolDirectorG = contests.get(19); assertEquals(thompsonSchoolDirectorG.name(), "Thompson R2-J School District Board of Education Director District G (4 Year Term)"); assertEquals((int) thompsonSchoolDirectorG.votesAllowed(), 1); assertEquals((int) thompsonSchoolDirectorG.winnersAllowed(), 1); - Contest cityOfLongmontJudge = contests.get(20); + final Contest cityOfLongmontJudge = contests.get(20); assertEquals(cityOfLongmontJudge.name(), "City of Longmont Municipal Court Judge - Frick"); assertEquals((int) cityOfLongmontJudge.votesAllowed(), 1); assertEquals((int) cityOfLongmontJudge.winnersAllowed(), 1); - Contest propHH = contests.get(21); + final Contest propHH = contests.get(21); assertEquals(propHH.name(),"Proposition HH (Statutory)"); assertEquals((int) propHH.votesAllowed(), 1); assertEquals((int) propHH.winnersAllowed(), 1); - Contest propII = contests.get(22); + final Contest propII = contests.get(22); assertEquals(propII.name(),"Proposition II (Statutory)"); assertEquals((int) propII.votesAllowed(), 1); assertEquals((int) propII.winnersAllowed(), 1); - Contest boulder1A = contests.get(23); + final Contest boulder1A = contests.get(23); assertEquals(boulder1A.name(),"Boulder County Ballot Issue 1A"); assertEquals((int) boulder1A.votesAllowed(), 1); assertEquals((int) boulder1A.winnersAllowed(), 1); - Contest boulder1B = contests.get(24); + final Contest boulder1B = contests.get(24); assertEquals(boulder1B.name(),"Boulder County Ballot Issue 1B"); assertEquals((int) boulder1B.votesAllowed(), 1); assertEquals((int) boulder1B.winnersAllowed(), 1); - Contest boulder2A = contests.get(25); + final Contest boulder2A = contests.get(25); assertEquals(boulder2A.name(), "City of Boulder Ballot Issue 2A"); assertEquals((int) boulder2A.votesAllowed(), 1); assertEquals((int) boulder2A.winnersAllowed(), 1); - Contest boulder2B = contests.get(26); + final Contest boulder2B = contests.get(26); assertEquals(boulder2B.name(), "City of Boulder Ballot Question 2B"); assertEquals((int) boulder2B.votesAllowed(), 1); assertEquals((int) boulder2B.winnersAllowed(), 1); - Contest boulder302 = contests.get(27); + final Contest boulder302 = contests.get(27); assertEquals(boulder302.name(), "City of Boulder Ballot Question 302"); assertEquals((int) boulder302.votesAllowed(), 1); assertEquals((int) boulder302.winnersAllowed(), 1); - Contest erie3A = contests.get(28); + final Contest erie3A = contests.get(28); assertEquals(erie3A.name(), "Town of Erie Ballot Question 3A"); assertEquals((int) erie3A.votesAllowed(), 1); assertEquals((int) erie3A.winnersAllowed(), 1); - Contest erie3B = contests.get(29); + final Contest erie3B = contests.get(29); assertEquals(erie3B.name(), "Town of Erie Ballot Question 3B"); assertEquals((int) erie3B.votesAllowed(), 1); assertEquals((int) erie3B.winnersAllowed(), 1); - Contest longmont3C = contests.get(30); + final Contest longmont3C = contests.get(30); assertEquals(longmont3C.name(), "City of Longmont Ballot Issue 3C"); assertEquals((int) longmont3C.votesAllowed(), 1); assertEquals((int) longmont3C.winnersAllowed(), 1); - Contest longmont3D = contests.get(31); + final Contest longmont3D = contests.get(31); assertEquals(longmont3D.name(), "City of Longmont Ballot Issue 3D"); assertEquals((int) longmont3D.votesAllowed(), 1); assertEquals((int) longmont3D.winnersAllowed(), 1); - Contest longmont3E = contests.get(32); + final Contest longmont3E = contests.get(32); assertEquals(longmont3E.name(), "City of Longmont Ballot Issue 3E"); assertEquals((int) longmont3E.votesAllowed(), 1); assertEquals((int) longmont3E.winnersAllowed(), 1); - Contest louisville2C = contests.get(33); + final Contest louisville2C = contests.get(33); assertEquals(louisville2C.name(), "City of Louisville Ballot Issue 2C"); assertEquals((int) louisville2C.votesAllowed(), 1); assertEquals((int) louisville2C.winnersAllowed(), 1); - Contest superior301 = contests.get(34); + final Contest superior301 = contests.get(34); assertEquals(superior301.name(), "Town of Superior Ballot Question 301"); assertEquals((int) superior301.votesAllowed(), 1); assertEquals((int) superior301.winnersAllowed(), 1); - Contest superiorHomeRule = contests.get(35); + final Contest superiorHomeRule = contests.get(35); assertEquals(superiorHomeRule.name(), "Town of Superior - Home Rule Charter Commission"); assertEquals((int) superiorHomeRule.votesAllowed(), 9); assertEquals((int) superiorHomeRule.winnersAllowed(), 9); - Contest nederlandEcoPass6A = contests.get(36); + final Contest nederlandEcoPass6A = contests.get(36); assertEquals(nederlandEcoPass6A.name(), "Nederland Eco Pass Public Improvement District Ballot Issue 6A"); assertEquals((int) nederlandEcoPass6A.votesAllowed(), 1); assertEquals((int) nederlandEcoPass6A.winnersAllowed(), 1); - Contest northMetroFire7A = contests.get(37); + final Contest northMetroFire7A = contests.get(37); assertEquals(northMetroFire7A.name(), "North Metro Fire Rescue District Ballot Issue 7A"); assertEquals((int) northMetroFire7A.votesAllowed(), 1); assertEquals((int) northMetroFire7A.winnersAllowed(), 1); // Check that the number of cvrs is correct. We have redacted CVRs, so the total is slightly // less than the actual official count of 119757. - List cvrs = getMatching(fromString("Boulder").id(), + final List cvrs = getMatching(fromString("Boulder").id(), CastVoteRecord.RecordType.UPLOADED).toList(); assertEquals(cvrs.size(), 118669); - CastVoteRecord cvr1 = cvrs.get(0); + final CastVoteRecord cvr1 = cvrs.get(0); // Check that the first cvr was correctly parsed. // We expect the first cvr to have voted on 13 contests (all Boulder), as follows: @@ -531,21 +533,29 @@ public void parseBoulder23Succeeds() throws IOException { // Make the ranked_ballot_interpretation report. final Map files = ExportQueries.sqlFiles(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - String q = files.get("ranked_ballot_interpretation"); + final String q = files.get("ranked_ballot_interpretation"); ExportQueries.csvOut(q, os); // Test for the proper reporting of some known invalid votes. - String boulderMayoralName = "City of Boulder Mayoral Candidates"; - String cvr = os.toString(); - assertTrue(StringUtils.contains(cvr, "county,contest,record_type,cvr_number,imprinted_id,raw_vote,valid_interpretation\n")); + final String boulderMayoralName = "City of Boulder Mayoral Candidates"; + final String cvr = os.toString(); + assertTrue(StringUtils.contains(cvr, + "county,contest,record_type,cvr_number,imprinted_id,raw_vote,valid_interpretation\n")); assertTrue(StringUtils.contains(cvr, - "Boulder,"+boulderMayoralName+",UPLOADED,140,108-1-32,\"\"\"Bob Yates(1)\"\",\"\"Bob Yates(2)\"\",\"\"Bob Yates(3)\"\",\"\"Bob Yates(4)\"\"\",\"\"\"Bob Yates\"\"")); + "Boulder,"+boulderMayoralName+",UPLOADED,140,108-1-32,\"\"\"Bob Yates(1)\"\"," + + "\"\"Bob Yates(2)\"\",\"\"Bob Yates(3)\"\",\"\"Bob Yates(4)\"\"\",\"\"\"Bob Yates\"\"")); assertTrue(StringUtils.contains(cvr, - "Boulder,"+boulderMayoralName+",UPLOADED,112680,108-100-48,\"\"\"Bob Yates(1)\"\",\"\"Nicole Speer(2)\"\",\"\"Aaron Brockett(3)\"\",\"\"Bob Yates(3)\"\",\"\"Paul Tweedlie(4)\"\"\",\"\"\"Bob Yates\"\",\"\"Nicole Speer\"\",\"\"Aaron Brockett\"\",\"\"Paul Tweedlie\"\"")); + "Boulder,"+boulderMayoralName+",UPLOADED,112680,108-100-48,\"\"\"Bob Yates(1)\"\"," + + "\"\"Nicole Speer(2)\"\",\"\"Aaron Brockett(3)\"\",\"\"Bob Yates(3)\"\"," + + "\"\"Paul Tweedlie(4)\"\"\",\"\"\"Bob Yates\"\",\"\"Nicole Speer\"\"," + + "\"\"Aaron Brockett\"\",\"\"Paul Tweedlie\"\"")); assertTrue(StringUtils.contains(cvr, - "Boulder,"+boulderMayoralName+",UPLOADED,107599,101-178-114,\"\"\"Bob Yates(1)\"\",\"\"Paul Tweedlie(1)\"\",\"\"Aaron Brockett(2)\"\",\"\"Paul Tweedlie(2)\"\",\"\"Paul Tweedlie(3)\"\",\"\"Paul Tweedlie(4)\"\"\",")); + "Boulder,"+boulderMayoralName+",UPLOADED,107599,101-178-114,\"\"\"Bob Yates(1)\"\"," + + "\"\"Paul Tweedlie(1)\"\",\"\"Aaron Brockett(2)\"\",\"\"Paul Tweedlie(2)\"\"," + + "\"\"Paul Tweedlie(3)\"\",\"\"Paul Tweedlie(4)\"\"\",")); assertTrue(StringUtils.contains(cvr, - "Boulder,"+boulderMayoralName+",UPLOADED,118738,101-190-124,\"\"\"Aaron Brockett(1)\"\",\"\"Bob Yates(1)\"\"\",")); + "Boulder,"+boulderMayoralName+",UPLOADED,118738,101-190-124," + + "\"\"\"Aaron Brockett(1)\"\",\"\"Bob Yates(1)\"\"\",")); } /** @@ -558,11 +568,11 @@ public void parseBoulder23Succeeds() throws IOException { @Transactional public void parseBadVoteForPluralityError() throws IOException { testUtils.log(LOGGER, "parseBadVoteForPluralityError"); - Path path = Paths.get(BAD_CSV_PATH + "badVoteForPlurality.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(BAD_CSV_PATH + "badVoteForPlurality.csv"); + final Reader reader = Files.newBufferedReader(path); // County sedgwick = fromString("Sedgwick"); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Sedgwick"), blank, true); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Sedgwick"), blank, true); assertTrue(parser.parse().success); } @@ -576,15 +586,15 @@ public void parseBadVoteForPluralityError() throws IOException { @Transactional public void parseWriteIns() throws IOException { testUtils.log(LOGGER, "parseWriteIns"); - Path path = Paths.get(WRITEIN_CSV_PATH + "WriteIns.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(WRITEIN_CSV_PATH + "WriteIns.csv"); + final Reader reader = Files.newBufferedReader(path); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Las Animas"), blank, true); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Las Animas"), blank, true); assertTrue(parser.parse().success); // There should be seven contests, one for each example way of writing write-in: // "Write-in", "Write-In", "Write in", "Write_in", "writeIn", "WRITEIN", "WRITE_IN" - List contests = forCounties(Set.of(fromString("Las Animas"))); + final List contests = forCounties(Set.of(fromString("Las Animas"))); assertEquals(7, contests.size()); for(int i=0 ; i < contests.size() ; i++) { diff --git a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/endpoint/GetAssertionsTests.java b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/endpoint/GetAssertionsTests.java index 1fefb9c2..df0f0bad 100644 --- a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/endpoint/GetAssertionsTests.java +++ b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/endpoint/GetAssertionsTests.java @@ -100,7 +100,7 @@ public class GetAssertionsTests extends TestClassWithDatabase { * Base url - this is set up to use the wiremock server, but could be set here to wherever you have the * raire-service running to test with that directly. */ - static String baseUrl; + private static String baseUrl; /** * Database init. diff --git a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java new file mode 100644 index 00000000..161dbfa4 --- /dev/null +++ b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java @@ -0,0 +1,150 @@ +package au.org.democracydevelopers.corla.query; + +import au.org.democracydevelopers.corla.communication.responseFromRaire.RaireServiceErrors; +import au.org.democracydevelopers.corla.model.GenerateAssertionsSummary; +import au.org.democracydevelopers.corla.util.TestClassWithDatabase; +import au.org.democracydevelopers.corla.util.testUtils; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.ext.ScriptUtils; +import org.testcontainers.jdbc.JdbcDatabaseDelegate; +import org.testng.annotations.Test; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import us.freeandfair.corla.persistence.Persistence; + +import java.util.Optional; + +import static au.org.democracydevelopers.corla.communication.responseFromRaire.RaireServiceErrors.RaireErrorCodes.TIED_WINNERS; +import static au.org.democracydevelopers.corla.endpoint.GenerateAssertions.UNKNOWN_WINNER; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertEquals; + +public class GenerateAssertionsSummaryQueriesTests extends TestClassWithDatabase { + + private static final Logger LOGGER = LogManager.getLogger(GenerateAssertionsSummaryQueriesTests.class); + + /** + * Container for the mock-up database. + */ + protected static PostgreSQLContainer postgres = createTestContainer(); + + /** + * Start the test container and establish persistence properties before the first test. + */ + @BeforeClass + public static void beforeAll() { + postgres.start(); + Persistence.setProperties(createHibernateProperties(postgres)); + + var containerDelegate = new JdbcDatabaseDelegate(postgres, ""); + ScriptUtils.runInitScript(containerDelegate, "SQL/simple-assertions.sql"); + ScriptUtils.runInitScript(containerDelegate, "SQL/summaries-generation-errors.sql"); + } + + /** + * After all test have run, stop the test container. + */ + @AfterClass + public static void afterAll() { + postgres.stop(); + } + + /** + * Correct retrieval of summary of successful assertion generation. + */ + @Test + public void retrieveSuccessSummary() { + testUtils.log(LOGGER, "retrieveSuccessSummary"); + + Optional summary = GenerateAssertionsSummaryQueries.matching("One NEB Assertion Contest"); + + assertTrue(summary.isPresent()); + assertEquals(summary.get().getWinner(), "Alice"); + assertEquals(summary.get().getError(), ""); + assertEquals(summary.get().getWarning(), ""); + assertEquals(summary.get().getMessage(), ""); + } + + /** + * Correct retrieval of winner from successful assertion generation. + */ + @Test + public void retrieveSuccessSummaryGetWinner() { + testUtils.log(LOGGER, "retrieveSuccessSummaryGetWinner"); + + String winner = GenerateAssertionsSummaryQueries.matchingWinner("One NEB Assertion Contest"); + assertEquals(winner, "Alice"); + } + + /** + * Correct retrieval of winner from successful assertion generation with a warning. + */ + @Test + public void retrieveSuccessSummaryWithWarning() { + testUtils.log(LOGGER, "retrieveSuccessSummaryWithWarning"); + + Optional summary + = GenerateAssertionsSummaryQueries.matching("Timeout trimming assertions Contest"); + + assertTrue(summary.isPresent()); + assertEquals(summary.get().getWinner(), "Bob"); + assertEquals(summary.get().getError(), ""); + assertEquals(summary.get().getWarning(), RaireServiceErrors.RaireErrorCodes.TIMEOUT_TRIMMING_ASSERTIONS.toString()); + assertEquals(summary.get().getMessage(), ""); + } + + /** + * Correct retrieval of summary of failed assertion generation, in this case a Tied winners error. + * Note that the raw result has a blank winner. + */ + @Test + public void retrieveFailureSummary() { + testUtils.log(LOGGER, "retrieveFailureSummary"); + + Optional summary = GenerateAssertionsSummaryQueries.matching("Tied winners Contest"); + + assertTrue(summary.isPresent()); + assertEquals(summary.get().getWinner(), ""); + assertEquals(summary.get().getError(), TIED_WINNERS.toString()); + assertEquals(summary.get().getWarning(), ""); + assertEquals(summary.get().getMessage(), "Tied winners: Alice, Bob"); + } + + /** + * Direct retrieval of UNKNOWN_WINNER from failed assertion generation. + * The matchingWinner function inserts UNKNOWN_WINNER when the winner is blank. + */ + @Test + public void retrieveFailureSummaryGetUnknownWinner() { + testUtils.log(LOGGER, "retrieveFailureSummaryGetUnknownWinner"); + + String winner = GenerateAssertionsSummaryQueries.matchingWinner("Tied winners Contest"); + assertEquals(winner, UNKNOWN_WINNER); + } + + /** + * Try to retrieve a summary that isn't there. + */ + @Test + public void nonExistentSummaryIsEmpty() { + testUtils.log(LOGGER, "nonExistentSummaryIsEmpty"); + + Optional summary = GenerateAssertionsSummaryQueries.matching("No Such Contest"); + + assertTrue(summary.isEmpty()); + } + + /** + * The winner of a summary that isn't there is UNKNOWN_WINNER. + */ + @Test + public void nonExistentSummaryIsUnknownWinner() { + testUtils.log(LOGGER, "nonExistentSummaryIsUnknownWinner"); + + String winner = GenerateAssertionsSummaryQueries.matchingWinner("No Such Contest"); + + assertEquals(winner, UNKNOWN_WINNER); + } +} diff --git a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/report/RankedBallotInterpretationReportTests.java b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/report/RankedBallotInterpretationReportTests.java index e5ea6ade..ba1d0895 100644 --- a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/report/RankedBallotInterpretationReportTests.java +++ b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/report/RankedBallotInterpretationReportTests.java @@ -52,7 +52,7 @@ /** * Test that a correct ranked vote interpretation report is produced, for a variety of IRV-related * parsing examples, including: - * ThreeCandidatesTenVotes - a constructed test file will all-valid IRV votes. + * ThreeCandidatesTenVotes - a constructed test file with all-valid IRV votes. * ThreeCandidatesTenInvalidVotes - a constructed test with invalid IRV ballots to check they are accepted and properly * interpreted. * An equivalent test using real data from Boulder '23 is in DominionCVRExportParserTests. @@ -63,8 +63,8 @@ public class RankedBallotInterpretationReportTests extends TestClassWithDatabase /** * Class-wide logger */ - private static final Logger LOGGER = LogManager.getLogger( - au.org.democracydevelopers.corla.report.RankedBallotInterpretationReportTests.class); + private static final Logger LOGGER + = LogManager.getLogger(RankedBallotInterpretationReportTests.class); /** * Container for the mock-up database. @@ -81,7 +81,7 @@ public static void beforeAll() { postgres.start(); Persistence.setProperties(createHibernateProperties(postgres)); - var containerDelegate = new JdbcDatabaseDelegate(postgres, ""); + final var containerDelegate = new JdbcDatabaseDelegate(postgres, ""); ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql"); } @@ -101,15 +101,15 @@ public void parseGuideToRaireExample3Succeeds() throws IOException { testUtils.log(LOGGER, "parseGuideToRaireExample3Succeeds"); // Parse the file. - Path path = Paths.get(TINY_CSV_PATH + "GuideToRAIREExample3.csv"); - Reader reader = Files.newBufferedReader(path); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Saguache"), blank, true); + final Path path = Paths.get(TINY_CSV_PATH + "GuideToRAIREExample3.csv"); + final Reader reader = Files.newBufferedReader(path); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Saguache"), blank, true); assertTrue(parser.parse().success); // Make the ranked_ballot_interpretation report. final Map files = ExportQueries.sqlFiles(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - String q = files.get("ranked_ballot_interpretation"); + final String q = files.get("ranked_ballot_interpretation"); ExportQueries.csvOut(q, os); // There should be no data, only headers, because all the IRV votes are valid. @@ -126,20 +126,20 @@ public void parseGuideToRaireExample3Succeeds() throws IOException { @Transactional public void parseThreeCandidatesTenInvalidVotesSucceeds() throws IOException { testUtils.log(LOGGER, "parseThreeCandidatesTenInvalidVotesSucceeds"); - Path path = Paths.get(TINY_CSV_PATH + "ThreeCandidatesTenInvalidVotes.csv"); - Reader reader = Files.newBufferedReader(path); + final Path path = Paths.get(TINY_CSV_PATH + "ThreeCandidatesTenInvalidVotes.csv"); + final Reader reader = Files.newBufferedReader(path); - DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Gilpin"), blank, true); + final DominionCVRExportParser parser = new DominionCVRExportParser(reader, fromString("Gilpin"), blank, true); assertTrue(parser.parse().success); // Make the ranked_ballot_interpretation report. final Map files = ExportQueries.sqlFiles(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - String q = files.get("ranked_ballot_interpretation"); + final String q = files.get("ranked_ballot_interpretation"); ExportQueries.csvOut(q, os); // There should be headers and 10 records matching the valid interpretations of all those invalid votes. - String cvr = os.toString(); + final String cvr = os.toString(); assertTrue(StringUtils.contains(cvr, "county,contest,record_type,cvr_number,imprinted_id,raw_vote,valid_interpretation\n")); assertTrue(StringUtils.contains(cvr, From 19fc26edae3fad4342dc98b58970fc78d931c71a Mon Sep 17 00:00:00 2001 From: vteague Date: Tue, 30 Jul 2024 17:36:06 +1000 Subject: [PATCH 2/2] Added class level comment and 'final' tag. --- ...GenerateAssertionsSummaryQueriesTests.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java index 161dbfa4..d2162e22 100644 --- a/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java +++ b/server/eclipse-project/src/test/java/au/org/democracydevelopers/corla/query/GenerateAssertionsSummaryQueriesTests.java @@ -21,6 +21,15 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertEquals; +/** + * Basic tests for proper functioning of GenerateAssertionsSummaryQueries. + * Test data is loaded from simple-assertions and (most usefully) summaries-generation-errors.sql. + * This tests successful retrieval of: + * - a summary of successful assertion generation, + * - the winner from a summary of successful assertion generation, + * - a warning (TIME_OUT_TRIMMING_ASSERTIONS) from a summary of successful assertion generation, + * - the correct errors from a collection of summaries of failed assertion generation. + */ public class GenerateAssertionsSummaryQueriesTests extends TestClassWithDatabase { private static final Logger LOGGER = LogManager.getLogger(GenerateAssertionsSummaryQueriesTests.class); @@ -74,7 +83,7 @@ public void retrieveSuccessSummary() { public void retrieveSuccessSummaryGetWinner() { testUtils.log(LOGGER, "retrieveSuccessSummaryGetWinner"); - String winner = GenerateAssertionsSummaryQueries.matchingWinner("One NEB Assertion Contest"); + final String winner = GenerateAssertionsSummaryQueries.matchingWinner("One NEB Assertion Contest"); assertEquals(winner, "Alice"); } @@ -85,13 +94,14 @@ public void retrieveSuccessSummaryGetWinner() { public void retrieveSuccessSummaryWithWarning() { testUtils.log(LOGGER, "retrieveSuccessSummaryWithWarning"); - Optional summary + final Optional summary = GenerateAssertionsSummaryQueries.matching("Timeout trimming assertions Contest"); assertTrue(summary.isPresent()); assertEquals(summary.get().getWinner(), "Bob"); assertEquals(summary.get().getError(), ""); - assertEquals(summary.get().getWarning(), RaireServiceErrors.RaireErrorCodes.TIMEOUT_TRIMMING_ASSERTIONS.toString()); + assertEquals(summary.get().getWarning(), + RaireServiceErrors.RaireErrorCodes.TIMEOUT_TRIMMING_ASSERTIONS.toString()); assertEquals(summary.get().getMessage(), ""); } @@ -103,7 +113,8 @@ public void retrieveSuccessSummaryWithWarning() { public void retrieveFailureSummary() { testUtils.log(LOGGER, "retrieveFailureSummary"); - Optional summary = GenerateAssertionsSummaryQueries.matching("Tied winners Contest"); + final Optional summary + = GenerateAssertionsSummaryQueries.matching("Tied winners Contest"); assertTrue(summary.isPresent()); assertEquals(summary.get().getWinner(), ""); @@ -120,7 +131,7 @@ public void retrieveFailureSummary() { public void retrieveFailureSummaryGetUnknownWinner() { testUtils.log(LOGGER, "retrieveFailureSummaryGetUnknownWinner"); - String winner = GenerateAssertionsSummaryQueries.matchingWinner("Tied winners Contest"); + final String winner = GenerateAssertionsSummaryQueries.matchingWinner("Tied winners Contest"); assertEquals(winner, UNKNOWN_WINNER); } @@ -131,7 +142,8 @@ public void retrieveFailureSummaryGetUnknownWinner() { public void nonExistentSummaryIsEmpty() { testUtils.log(LOGGER, "nonExistentSummaryIsEmpty"); - Optional summary = GenerateAssertionsSummaryQueries.matching("No Such Contest"); + final Optional summary + = GenerateAssertionsSummaryQueries.matching("No Such Contest"); assertTrue(summary.isEmpty()); } @@ -143,7 +155,7 @@ public void nonExistentSummaryIsEmpty() { public void nonExistentSummaryIsUnknownWinner() { testUtils.log(LOGGER, "nonExistentSummaryIsUnknownWinner"); - String winner = GenerateAssertionsSummaryQueries.matchingWinner("No Such Contest"); + final String winner = GenerateAssertionsSummaryQueries.matchingWinner("No Such Contest"); assertEquals(winner, UNKNOWN_WINNER); }