diff --git a/src/test/java/fr/packageviewer/ArchTest.java b/src/test/java/fr/packageviewer/ArchTest.java index 62f5ba0..3d03774 100644 --- a/src/test/java/fr/packageviewer/ArchTest.java +++ b/src/test/java/fr/packageviewer/ArchTest.java @@ -1,85 +1,19 @@ package fr.packageviewer; import fr.packageviewer.distribution.ArchDistribution; -import fr.packageviewer.distribution.Distribution; import fr.packageviewer.pack.Package; -import fr.packageviewer.pack.SearchedPackage; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.concurrent.ExecutionException; - -public class ArchTest { - - @Test - public void testBasicQueryDoNotFail(){ - Distribution arch = new ArchDistribution(); - arch.getPackageTree("bash", 0); +public class ArchTest extends DistroTest { + @Override + protected ArchDistribution createInstance() { + return new ArchDistribution(); } @Test - public void testBashPackageHasNameBash() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("bash", 0).get(); - Assertions.assertEquals(pack.getName(), "bash"); - } - @Test - public void testQueryWithDepth0HasNoDeps() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("bash", 0).get(); - Assertions.assertEquals(pack.getDeps().size(), 0); - } - @Test - public void testQueryWithDepth1hasOneLevelOfDeps() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("bash", 1).get(); - Assertions.assertNotEquals(pack.getDeps().size(), 0); - for(Package dep : pack.getDeps()){ - Assertions.assertEquals(dep.getDeps().size(), 0); - } - } - - @Test - public void testBashIsInCore() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("bash", 1).get(); + public void testBashIsInCore() { + Package pack = helperGetPackageTree("bash", 0); Assertions.assertEquals(pack.getRepo(), "core"); } - - @Test - public void testBashDescriptionIsNotEmpty() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("bash", 1).get(); - Assertions.assertFalse(pack.getDescription().isEmpty()); - } - @Test - public void testBashVersionIsNotEmpty() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("bash", 1).get(); - Assertions.assertFalse(pack.getVersion().isEmpty()); - } - - @Test - public void testInvalidPackageReturnsNull() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Package pack = arch.getPackageTree("lndhsgudw", 1).get(); - Assertions.assertNull(pack); - } - - @Test - public void testThatBashSearchReturnsResults() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - Assertions.assertNotEquals(arch.searchPackage("bash").get().size(), 0); - } - @Test - public void testThatBashSearchContainsBash() throws ExecutionException, InterruptedException { - Distribution arch = new ArchDistribution(); - for(SearchedPackage pack : arch.searchPackage("bash").get()){ - if(pack.getName().equals("bash")){ - Assertions.assertTrue(true); - return; - } - } - Assertions.fail("No package named 'bash' in results"); - } } diff --git a/src/test/java/fr/packageviewer/DistroTest.java b/src/test/java/fr/packageviewer/DistroTest.java new file mode 100644 index 0000000..2f63cf9 --- /dev/null +++ b/src/test/java/fr/packageviewer/DistroTest.java @@ -0,0 +1,96 @@ +package fr.packageviewer; + +import fr.packageviewer.distribution.ArchDistribution; +import fr.packageviewer.distribution.Distribution; +import fr.packageviewer.pack.Package; +import fr.packageviewer.pack.SearchedPackage; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public abstract class DistroTest { + + protected abstract T createInstance(); + protected List helperSearchPackage(String packageName){ + Distribution distribution = createInstance(); + Future> future = distribution.searchPackage(packageName); + try{ + return future.get(); + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + } + protected Package helperGetPackageTree(String packageName, int depth){ + Distribution distribution = createInstance(); + Future future = distribution.getPackageTree(packageName, depth); + try{ + return future.get(); + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testBasicQueryDoNotFail(){ + helperGetPackageTree("bash", 0); + } + + @Test + public void testBashPackageHasNameBash() throws ExecutionException, InterruptedException { + Distribution arch = new ArchDistribution(); + Package pack = arch.getPackageTree("bash", 0).get(); + Assertions.assertEquals(pack.getName(), "bash"); + } + + @Test + public void testQueryWithDepth0HasNoDeps() { + Distribution arch = new ArchDistribution(); + Package pack = helperGetPackageTree("bash", 0); + Assertions.assertEquals(pack.getDeps().size(), 0); + } + + @Test + public void testQueryWithDepth1hasOneLevelOfDeps() { + Package pack = helperGetPackageTree("bash", 1); + Assertions.assertNotEquals(pack.getDeps().size(), 0); + for(Package dep : pack.getDeps()){ + Assertions.assertEquals(dep.getDeps().size(), 0); + } + } + + @Test + public void testBashDescriptionIsNotEmpty() { + Package pack = helperGetPackageTree("bash", 1); + Assertions.assertFalse(pack.getDescription().isEmpty()); + } + + @Test + public void testBashVersionIsNotEmpty() { + Package pack = helperGetPackageTree("bash", 1); + Assertions.assertFalse(pack.getVersion().isEmpty()); + } + + @Test + public void testInvalidPackageReturnsNull() { + Package pack = helperGetPackageTree("lndhsgudw", 1); + Assertions.assertNull(pack); + } + + @Test + public void testThatBashSearchReturnsResults() { + Assertions.assertNotEquals(helperSearchPackage("bash").size(), 0); + } + @Test + public void testThatBashSearchContainsBash() { + for(SearchedPackage pack : helperSearchPackage("bash")){ + if(pack.getName().equals("bash")){ + Assertions.assertTrue(true); + return; + } + } + Assertions.fail("No package named 'bash' in results"); + } +}