Skip to content

Commit

Permalink
test: add more tests to verify deserialisation (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 authored Aug 1, 2023
1 parent 3c1a3c3 commit 510e57d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
26 changes: 22 additions & 4 deletions watchdog-agent/src/test/java/OptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.algomaster99.Options;
import io.github.algomaster99.terminator.commons.fingerprint.Fingerprint;
import io.github.algomaster99.terminator.commons.fingerprint.Jar;
import io.github.algomaster99.terminator.commons.fingerprint.Maven;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -15,12 +16,29 @@ public class OptionsTest {
class ParseFingerprint {
@Test
void maven() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
List<Fingerprint> fingerprints = deserializeFingerprints("src/test/resources/fingerprints/maven.jsonl");
assertThat(fingerprints).hasOnlyElementsOfType(Maven.class).size().isEqualTo(2);
}

@Test
void jar() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
List<Fingerprint> fingerprints = deserializeFingerprints("src/test/resources/fingerprints/jar.jsonl");
assertThat(fingerprints).hasOnlyElementsOfType(Jar.class).size().isEqualTo(7);
}

@Test
void maven_jar() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
List<Fingerprint> fingerprints = deserializeFingerprints("src/test/resources/fingerprints/maven_jar.jsonl");
assertThat(fingerprints).elements(0, 2).hasOnlyElementsOfType(Maven.class);
assertThat(fingerprints).elements(3, 5).hasOnlyElementsOfType(Jar.class);
}

private List<Fingerprint> deserializeFingerprints(String pathname)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
Method method = Options.class.getDeclaredMethod("parseFingerprints", File.class);
method.setAccessible(true);
Object result = method.invoke(null, new File("src/test/resources/fingerprints/maven.jsonl"));

List<Fingerprint> fingerprints = (List<Fingerprint>) result;
assertThat(fingerprints).hasOnlyElementsOfType(Maven.class).size().isEqualTo(2);
Object result = method.invoke(null, new File(pathname));
return (List<Fingerprint>) result;
}
}
}
7 changes: 7 additions & 0 deletions watchdog-agent/src/test/resources/fingerprints/jar.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/Java","classFileVersion":"55.0","hash":"b5ffd375494a8a018285fdd6532aecbfd2be757b2347fe58d38b6ef486dea941","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/DroppedPropertiesSensor","classFileVersion":"55.0","hash":"343e442953f0222644ce6aa3ce46649da747022fa0176c6b0a2ee153589cbb6a","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/api/package-info","classFileVersion":"55.0","hash":"e072966b9c3e77b06678b56e61f040e1b54bf5d8615a4cff183e014c4aa60492","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/data/UnitTestClassReport","classFileVersion":"55.0","hash":"a058963df7e50c2b0e9244c5dca4da4871819d2e41b3fa9572fb68d5d42cd5fe","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/data/UnitTestResult","classFileVersion":"55.0","hash":"22869f19e555e562afc53bba32fe528df1d668505545b00ce4377ec2021a857b","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/data/UnitTestIndex","classFileVersion":"55.0","hash":"bf8e6c60a7ee628711a9c4f6580aba31c8a151be0d9550c46f632a374d4669d0","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/surefire/SurefireJavaParser","classFileVersion":"55.0","hash":"254f59d4f9b67da425af0ab13572da31a9d3201f3313795cbd1c2c716a3b0ebf","algorithm":"SHA256"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"groupId":"com.google.j2objc","artifactId":"j2objc-annotations","version":"2.8","className":"com/google/j2objc/annotations/WeakOuter","classFileVersion":"51.0","hash":"7762fe98c21931d5ca5ed99d574cfcef2aa430863ac74258a40955cf0a215d50","algorithm":"SHA256"}
{"groupId":"com.google.j2objc","artifactId":"j2objc-annotations","version":"2.8","className":"com/google/j2objc/annotations/LoopTranslation$LoopStyle","classFileVersion":"51.0","hash":"9ff5c8ce518e62b544dac56a0a51b62e44f03d1907519da4b3344d5ab709a2c4","algorithm":"SHA256"}
{"groupId":"com.google.j2objc","artifactId":"j2objc-annotations","version":"2.8","className":"com/google/j2objc/annotations/J2ObjCIncompatible","classFileVersion":"51.0","hash":"ca2dd3ff4f3e025414279ee7102bfdbe04c7b035b1d9adf62180b19b91f285ad","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/package-info","classFileVersion":"55.0","hash":"3e844019225a05bf7bbced91024d3780a3c39d375c4eaeee22f1adb68d156ecd","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/JavaSonarWayProfile","classFileVersion":"55.0","hash":"d235f7ac1c020656dcfc91d9688ffe9160b145a1cf2c6d235152d7fc48a4f06f","algorithm":"SHA256"}
{"path":"/home/aman/.cache/sorald/sonar-java-plugin.jar","className":"org/sonar/plugins/java/JavaPlugin","classFileVersion":"55.0","hash":"f15bf5c696718a521b9234bf893dbb50b10e10fa0a6201d2ec09c0ec92c4f81d","algorithm":"SHA256"}

0 comments on commit 510e57d

Please sign in to comment.