Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update acceptance test report to include changes in WARNINGS. #1354

Merged
merged 9 commits into from
Mar 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@

package org.mobilitydata.gtfsvalidator.model;

import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.mobilitydata.gtfsvalidator.io.ValidationReportDeserializer;

/**
Expand All @@ -45,7 +41,6 @@ public class ValidationReport {
.serializeSpecialFloatingPointValues()
.create();
private final Set<NoticeReport> notices;
private final transient Map<String, NoticeReport> errorNoticeByCode;

/**
* Public constructor needed for deserialization by {@code ValidationReportDeserializer}. Only
Expand All @@ -55,13 +50,6 @@ public class ValidationReport {
*/
public ValidationReport(Set<NoticeReport> noticeReports) {
this.notices = Collections.unmodifiableSet(noticeReports);
Map<String, NoticeReport> errorNoticeByCode = new HashMap<>();
for (NoticeReport noticeReport : noticeReports) {
if (noticeReport.isError()) {
errorNoticeByCode.put(noticeReport.getCode(), noticeReport);
}
}
this.errorNoticeByCode = errorNoticeByCode;
}

/**
Expand All @@ -77,63 +65,10 @@ public static ValidationReport fromPath(Path path) throws IOException {
}
}

/** Returns all error notice reports {@code NoticeReport} of this {@code ValidationReport}. */
public Set<NoticeReport> getErrorNotices() {
public Set<NoticeReport> getNotices() {
return notices;
}

/**
* Returns the error {@code NoticeReport} related to the {@code Notice} whose notice code has been
* provided as parameter. If the requested notice code is not present in this {@code
* ValidationReport}, null is returned.
*
* @param noticeCode the notice code related to the {@code NoticeReport} to be returned
*/
@Nullable
public NoticeReport getErrorNoticeReportByNoticeCode(String noticeCode) {
return errorNoticeByCode.get(noticeCode);
}

/**
* Compares two validation reports: returns true if they contain the same set of error codes.
*
* @param otherValidationReport the other {@code ValidationReport}.
* @return true if the two {@code ValidationReport} contain the same set of error codes, false
* otherwise.
*/
public boolean hasSameErrorCodes(ValidationReport otherValidationReport) {
return this.errorNoticeByCode.keySet().equals(otherValidationReport.errorNoticeByCode.keySet());
}

/**
* Returns the listing of new error codes introduced by the other {@code ValidationReport} passed
* as parameter, e.g. if this {@code ValidationReport} has the following error codes:
*
* <ul>
* <li>invalid_phone_number;
* <li>number_out_of_range;
* </ul>
*
* <p>and the other {@code ValidationReport} has the following error codes:
*
* <ul>
* <li>invalid_phone_number;
* <li>number_out_of_range;
* <li>invalid_email_address;
* <li>invalid_url;
* </ul>
*
* <p>then this returns a {@code Set} that contains the two new errors codes
* (invalid_email_address, invalid_url) not present in this {@code ValidationReport}
*
* @param other the other {@code ValidationReport}
* @return the listing of new error codes introduced by the other {@code ValidationReport} passed
* as parameter.
*/
public Set<String> getNewErrorsListing(ValidationReport other) {
return Sets.difference(other.errorNoticeByCode.keySet(), this.errorNoticeByCode.keySet());
}

/**
* Determines if two validation reports are equal regardless of the order of the fields in the set
* of {@code NoticeReport}.
Expand All @@ -149,7 +84,7 @@ public boolean equals(Object other) {
}
if (other instanceof ValidationReport) {
ValidationReport otherReport = (ValidationReport) other;
return getErrorNotices().equals(otherReport.getErrorNotices());
return this.notices.equals(otherReport.notices);
}
return false;
}
Expand Down
Loading