aboutsummaryrefslogtreecommitdiffstats
path: root/abi-check-plugin
diff options
context:
space:
mode:
authorIlpo Ruotsalainen <ilpo.ruotsalainen@oath.com>2018-11-30 15:35:31 +0100
committerIlpo Ruotsalainen <ilpo.ruotsalainen@oath.com>2018-11-30 15:35:31 +0100
commitfa30c3ee5f8d3191b9fdd9b06fb3314e101337f3 (patch)
treeaf43958cc655b066553fdea25119bad3c7c4f1bf /abi-check-plugin
parentfda36d376057cbe710f89ec02d865739e02f1e61 (diff)
Improve test coverage.
Diffstat (limited to 'abi-check-plugin')
-rw-r--r--abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java31
1 files changed, 17 insertions, 14 deletions
diff --git a/abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java b/abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java
index c308163c108..5aa8ed2d770 100644
--- a/abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java
+++ b/abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java
@@ -11,6 +11,7 @@ import com.google.common.collect.Iterables;
import com.yahoo.abicheck.classtree.ClassFileTree;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
import java.util.Collections;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -21,21 +22,23 @@ public class ClassFileTreeTest {
@Test
public void testJarParsing() throws IOException {
JarFile jarFile = mock(JarFile.class);
- JarEntry jarEntry = new JarEntry("com/yahoo/Test.class");
+ JarEntry classJarEntry = new JarEntry("com/yahoo/Test.class");
+ JarEntry dirJarEntry = new JarEntry("com/yahoo/");
InputStream jarEntryStream = mock(InputStream.class);
- when(jarFile.entries()).thenReturn(Collections
- .enumeration(Collections.singleton(jarEntry)));
- when(jarFile.getInputStream(jarEntry)).thenReturn(jarEntryStream);
+ when(jarFile.entries())
+ .thenReturn(Collections.enumeration(Arrays.asList(dirJarEntry, classJarEntry)));
+ when(jarFile.getInputStream(classJarEntry)).thenReturn(jarEntryStream);
- ClassFileTree cft = ClassFileTree.fromJar(jarFile);
- ClassFileTree.Package com = Iterables.getOnlyElement(cft.getRootPackages());
- assertThat(com.getFullyQualifiedName(), equalTo("com"));
- assertThat(com.getClassFiles(), empty());
- ClassFileTree.Package yahoo = Iterables.getOnlyElement(com.getSubPackages());
- assertThat(yahoo.getFullyQualifiedName(), equalTo("com.yahoo"));
- assertThat(yahoo.getSubPackages(), empty());
- ClassFileTree.ClassFile testClassFile = Iterables.getOnlyElement(yahoo.getClassFiles());
- assertThat(testClassFile.getName(), equalTo("Test.class"));
- assertThat(testClassFile.getInputStream(), sameInstance(jarEntryStream));
+ try (ClassFileTree cft = ClassFileTree.fromJar(jarFile)) {
+ ClassFileTree.Package com = Iterables.getOnlyElement(cft.getRootPackages());
+ assertThat(com.getFullyQualifiedName(), equalTo("com"));
+ assertThat(com.getClassFiles(), empty());
+ ClassFileTree.Package yahoo = Iterables.getOnlyElement(com.getSubPackages());
+ assertThat(yahoo.getFullyQualifiedName(), equalTo("com.yahoo"));
+ assertThat(yahoo.getSubPackages(), empty());
+ ClassFileTree.ClassFile testClassFile = Iterables.getOnlyElement(yahoo.getClassFiles());
+ assertThat(testClassFile.getName(), equalTo("Test.class"));
+ assertThat(testClassFile.getInputStream(), sameInstance(jarEntryStream));
+ }
}
}