Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Jun 28, 2024
1 parent 07a6beb commit c66ea0d
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public InputStream getItemStream(String itemName) throws IOException {
return getStreamFromReference(this.itemMap.get(itemName));
}

abstract protected InputStream getStreamFromReference(final L reference) throws IOException;
protected abstract InputStream getStreamFromReference(final L reference) throws IOException;

/**
* { @inheritDoc }
Expand Down Expand Up @@ -206,7 +206,7 @@ public static File createTempFileFromCorpus(final URL downloadLoc, final String
System.out.println("Downloading: " + downloadLoc + ", to temp:" + tempFile);
int totalBytes = 0;
try (OutputStream output = new FileOutputStream(tempFile);
InputStream corpusInput = handleRedirects(downloadLoc);) {
InputStream corpusInput = handleRedirects(downloadLoc)) {
byte[] buffer = new byte[8 * 1024];
int bytesRead;
while ((bytesRead = corpusInput.read(buffer)) != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private static CorpusItemId fromCode(final Specification specification,
} else {
if (part.contains(" ")) {
part = part.substring(part.lastIndexOf(" ") + 1);
} else if (part.equalsIgnoreCase("isartor")) {
} else if ("isartor".equalsIgnoreCase(part)) {
continue;
}
builder.append(separator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void getFailedPolicyComplianceFiles(Map<String, List<FailedPolicyCheck>>
}

public static void printResult(Map<String, List<FailedPolicyCheck>> failedFiles) {
if (failedFiles.size() > 0) {
if (!failedFiles.isEmpty()) {
System.out.println("Some files is not compliant with policy: ");
for (Map.Entry<String, List<FailedPolicyCheck>> entry : failedFiles.entrySet()) {
System.out.println(entry.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ResultSetDetailsImpl implements ResultSetDetails {
@XmlElement(name = "dependency")
private final Set<ReleaseDetails> dependencies;
private ResultSetDetailsImpl() {
this(Collections.<ReleaseDetails> emptySet());
this(Collections.emptySet());
}

private ResultSetDetailsImpl(Set<ReleaseDetails> dependencies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static ResultSet validateCorpus(final TestCorpus corpus, final PDFAValida
}
ValidationResult result = currentValidator.validate(loader);
long memUsed = (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / MEGABYTE);
maxMemUse = (memUsed > maxMemUse) ? memUsed : maxMemUse;
maxMemUse = Math.max(memUsed, maxMemUse);
results.add(new Result(id, result, jobTimer.stop(), memUsed));
} catch (Throwable e) {
LOG.log(Level.SEVERE, String.format("Caught throwable testing %s from corpus %s", itemName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public final class RuleDirectory implements Directory<RuleId, Rule> {

private final Registry<RuleId, Rule> rules = new MapBackedRegistry<>(
Collections.<RuleId, Rule>emptyMap());
Collections.emptyMap());
private final Set<Variable> variables = new HashSet<>();
private final PDFAFlavour flavour;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author <a href="mailto:[email protected]">Carl Wilson</a>
*/
public class ZipBackedTestCorpus extends AbstractTestCorpus<ZipEntry> {
private final static String PDF_SUFFIX = ".pdf";
private static final String PDF_SUFFIX = ".pdf";
private final ZipFile zipSource;

private ZipBackedTestCorpus(final CorpusDetails details, final Corpus type, final File zipSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ private static final EnumMap<Corpus, EnumMap<PDFAFlavour, Set<String>>> createEx
if (expected == null)
continue;
expectedFailureSets.computeIfAbsent(corpus,
k -> new EnumMap<PDFAFlavour, Set<String>>(PDFAFlavour.class));
expectedFailureSets.get(corpus).computeIfAbsent(flavour, k -> new HashSet<String>(expected));
k -> new EnumMap<>(PDFAFlavour.class));
expectedFailureSets.get(corpus).computeIfAbsent(flavour, k -> new HashSet<>(expected));
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static boolean featureTreeNodesEqual(FeatureTreeNode node1,

for (Map.Entry<String, String> entry : node1Attrs.entrySet()) {
String key = entry.getKey();
if (!key.equals("id")) {
if (!"id".equals(key)) {
if (!entry.getValue().equals(node2Attrs.get(key))) {
failMessages.push("Different value of attribute " + key +
" in nodes: " + node1 + " " + node2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,20 @@ public void testFailFastValidator() throws IOException, JAXBException, ModelPars
continue;
}
if (index == failedMax) {
assertTrue(resultsComparisonMessage(veraCorpus
assertEquals(resultsComparisonMessage(veraCorpus
.getDetails().getName(), itemName,
profile.getPDFAFlavour().toString(),
result, failFastResult),
result.equals(failFastResult));
profile.getPDFAFlavour().toString(),
result, failFastResult), result, failFastResult);
} else if ((index == (failedMax -1)) && (getMaxFailureOrdinal(result) == result.getTotalAssertions())) {
assertTrue(resultsComparisonMessage(veraCorpus
.getDetails().getName(), itemName,
assertEquals(resultsComparisonMessage(veraCorpus
.getDetails().getName(), itemName,
profile.getPDFAFlavour().toString(),
result, failFastResult),
result.equals(failFastResult));
result, failFastResult), result, failFastResult);
} else if (index < failedMax) {
assertFalse(resultsComparisonMessage(veraCorpus
.getDetails().getName(), itemName,
assertNotEquals(resultsComparisonMessage(veraCorpus
.getDetails().getName(), itemName,
profile.getPDFAFlavour().toString(),
result, failFastResult), result.equals(failFastResult));
result, failFastResult), result, failFastResult);

}
}
Expand Down Expand Up @@ -215,22 +213,18 @@ public void testModelConsistency() throws IOException, ValidationException,

// The results of the two separate validators should be the
// same (this works)
assertTrue(
resultsComparisonMessage(veraCorpus.getDetails()
assertEquals(resultsComparisonMessage(veraCorpus.getDetails()
.getName(), itemName, profile
.getPDFAFlavour().toString(), firstResult,
secondResult),
checkResult.equals(secondResult));
secondResult), checkResult, secondResult);
// The results of the same validator should be the same
// (this doesn't)
// The act of validation changes something in the
// model......
assertTrue(
resultsComparisonMessage(veraCorpus.getDetails()
assertEquals(resultsComparisonMessage(veraCorpus.getDetails()
.getName(), itemName, profile
.getPDFAFlavour().toString(), firstResult,
secondResult),
firstResult.equals(secondResult));
secondResult), firstResult, secondResult);
}
}
}
Expand Down Expand Up @@ -260,7 +254,7 @@ private String resultsMessage(final String corpus, final String itemName,
writer.write("\nSet<ValidationResults>.size()=" + results.size()
+ "\nResults:\n");

if (results.size() > 0) {
if (!results.isEmpty()) {
for (ValidationResult result : results) {
XmlSerialiser.toXml(result, writer, true, true);
}
Expand Down

0 comments on commit c66ea0d

Please sign in to comment.