diff options
author | Ilpo Ruotsalainen <ilpo.ruotsalainen@oath.com> | 2018-11-29 16:45:21 +0100 |
---|---|---|
committer | Ilpo Ruotsalainen <ilpo.ruotsalainen@oath.com> | 2018-11-29 16:45:21 +0100 |
commit | bcda0a820761be12200312e85dba17a1dda79f5a (patch) | |
tree | b1e6c435ffaae1012599cffcfbc55bd350596fc3 | |
parent | d3d97e192d05227c9614aab9e880d8f06eab66da (diff) |
Add unit test for ClassFileTree.
-rw-r--r-- | abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java | 41 |
1 files changed, 41 insertions, 0 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 new file mode 100644 index 00000000000..c308163c108 --- /dev/null +++ b/abi-check-plugin/src/test/java/com/yahoo/abicheck/ClassFileTreeTest.java @@ -0,0 +1,41 @@ +package com.yahoo.abicheck; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.common.collect.Iterables; +import com.yahoo.abicheck.classtree.ClassFileTree; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import org.junit.jupiter.api.Test; + +public class ClassFileTreeTest { + + @Test + public void testJarParsing() throws IOException { + JarFile jarFile = mock(JarFile.class); + JarEntry jarEntry = new JarEntry("com/yahoo/Test.class"); + InputStream jarEntryStream = mock(InputStream.class); + when(jarFile.entries()).thenReturn(Collections + .enumeration(Collections.singleton(jarEntry))); + when(jarFile.getInputStream(jarEntry)).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)); + } +} |