From ecb7f6b7de1d3d34b2b520d955e6d0afa9f8566e Mon Sep 17 00:00:00 2001 From: jhouse Date: Mon, 6 Jan 2020 10:06:34 +0900 Subject: [PATCH] Cleaning up possible null pointer Cleaning up tests Cleaning up poms --- Core/pom.xml | 6 - GapsWeb/pom.xml | 5 - .../validator/PlexPropertiesValidator.java | 4 +- GapsWeb/src/main/resources/application.yaml | 2 +- .../gaps/GapsSearchServiceTest.java | 118 +----------------- .../com/jasonhhouse/gaps/GapsServiceTest.java | 40 ++++++ pom.xml | 35 ++++++ 7 files changed, 80 insertions(+), 130 deletions(-) create mode 100644 GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsServiceTest.java diff --git a/Core/pom.xml b/Core/pom.xml index 79c50e1..d6a58b7 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -15,32 +15,26 @@ org.jetbrains annotations - 17.0.0 com.squareup.okhttp3 okhttp - 4.2.0 org.apache.commons commons-lang3 - 3.9 org.apache.commons commons-collections4 - 4.4 org.hibernate.validator hibernate-validator - 6.0.18.Final - compile diff --git a/GapsWeb/pom.xml b/GapsWeb/pom.xml index 7bdcfb9..e896204 100644 --- a/GapsWeb/pom.xml +++ b/GapsWeb/pom.xml @@ -85,19 +85,16 @@ com.squareup.okhttp3 okhttp - 4.2.0 org.apache.commons commons-lang3 - 3.9 org.apache.commons commons-collections4 - 4.4 @@ -109,7 +106,6 @@ org.hibernate.validator hibernate-validator - 6.0.17.Final @@ -127,7 +123,6 @@ org.jetbrains annotations - 17.0.0 diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexPropertiesValidator.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexPropertiesValidator.java index 0a1c3dd..b112261 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexPropertiesValidator.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexPropertiesValidator.java @@ -39,9 +39,7 @@ public class PlexPropertiesValidator implements Validator { if (plexSearch.getPort() == null) { errors.rejectValue("port", "port.empty"); - } - - if (plexSearch.getPort() < 0) { + } else if (plexSearch.getPort() < 0) { errors.rejectValue("port", "port.belowRange"); } diff --git a/GapsWeb/src/main/resources/application.yaml b/GapsWeb/src/main/resources/application.yaml index 92f7da6..7ab740d 100644 --- a/GapsWeb/src/main/resources/application.yaml +++ b/GapsWeb/src/main/resources/application.yaml @@ -26,7 +26,7 @@ logging: level: root: INFO server: - port: 8484 + port: 8443 compression: enabled: true mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json diff --git a/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsSearchServiceTest.java b/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsSearchServiceTest.java index 16b0841..1d7dd33 100644 --- a/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsSearchServiceTest.java +++ b/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsSearchServiceTest.java @@ -32,9 +32,6 @@ class GapsSearchServiceTest { private GapsUrlGeneratorTest gapsUrlGeneratorTest; private GapsSearchService gapsSearch; - @Mock - private GapsService gapsService; - @Mock private IoService ioService; @@ -42,6 +39,9 @@ class GapsSearchServiceTest { void setup() throws Exception { gapsUrlGeneratorTest = new GapsUrlGeneratorTest(); SimpMessagingTemplate template = new SimpMessagingTemplate((message, l) -> true); + + GapsService gapsService = new GapsServiceTest(); + gapsSearch = new GapsSearchService(gapsUrlGeneratorTest, template, ioService, gapsService); // Create a MockWebServer. These are lean enough that you can create a new @@ -74,128 +74,16 @@ class GapsSearchServiceTest { }, "Should throw exception when not searching from folder and Plex"); } - @Test - void searchPlexGapsEmptyOtherwise() throws Exception { - gapsSearch.run(); - - List recommended = gapsSearch.getRecommendedMovies(); - Assertions.assertEquals(recommended.size(), 0, "Shouldn't have found any movies"); - } - - /* @Test - void emptyLibraryXmlFromPlex() { - HttpUrl baseUrl = gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.PLEX_EMPTY_URL); - - Assertions.assertThrows(IllegalStateException.class, () -> gapsSearch.getPlexLibraries(baseUrl), "Should throw exception with for an empty body"); - }*/ - - /*@Test - void validLibraryXmlFromPlex() { - HttpUrl baseUrl = gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.FULL_PLEX_XML_URL); - - Set plexLibraries = gapsSearch.getPlexLibraries(baseUrl); - Assertions.assertEquals(plexLibraries.size(), 2, "Should have found exactly two libraries"); - }*/ - - /*@Test - void badLibraryXmlFromPlex() { - HttpUrl baseUrl = gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.MISSING_TYPE_PLEX_URL); - - Assertions.assertThrows(ResponseStatusException.class, () -> gapsSearch.getPlexLibraries(baseUrl), "Should throw exception for missing 'type' node inside /MediaContainer/Directory element"); - }*/ - - /* @Test - void missingTitleFromPlex() { - HttpUrl baseUrl = gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.MISSING_TITLE_PLEX_URL); - - Assertions.assertThrows(ResponseStatusException.class, () -> gapsSearch.getPlexLibraries(baseUrl), "Should throw exception for missing 'title' node inside /MediaContainer/Directory element"); - }*/ - - /* @Test - void missingKeyFromPlex() { - HttpUrl baseUrl = gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.MISSING_KEY_PLEX_URL); - - Assertions.assertThrows(ResponseStatusException.class, () -> { - gapsSearch.getPlexLibraries(baseUrl); - }, "Should throw exception for missing 'key' node inside /MediaContainer/Directory element"); - }*/ - - /* @Test - void nonNumberKeyFromPlex() { - HttpUrl baseUrl = gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.NON_NUMBER_KEY_FROM_PLEX_URL); - - Assertions.assertThrows(ResponseStatusException.class, () -> gapsSearch.getPlexLibraries(baseUrl), "Should throw exception for 'key' node not being a number inside /MediaContainer/Directory element"); - }*/ - @Test void noBodyMovieXmlFromPlex() { gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.PLEX_EMPTY_URL); - - List movieUrls = new ArrayList<>(); - movieUrls.add(GapsUrlGeneratorTest.PLEX_EMPTY_URL); - Assertions.assertThrows(ResponseStatusException.class, () -> gapsSearch.run(), "Should throw exception that the body was empty"); } - @Test - void emptyBodyMovieXmlFromPlex() { - gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.NO_MOVIE_PLEX_URL); - - List movieUrls = new ArrayList<>(); - movieUrls.add(GapsUrlGeneratorTest.NO_MOVIE_PLEX_URL); - - gapsSearch.run(); - - List recommended = gapsSearch.getRecommendedMovies(); - Assertions.assertEquals(recommended.size(), 0, "Shouldn't have found any movies"); - } - @Test void emptyMovieXmlFromPlex() { gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.EMPTY_MOVIE_PLEX_URL); - - List movieUrls = new ArrayList<>(); - movieUrls.add(GapsUrlGeneratorTest.EMPTY_MOVIE_PLEX_URL); - Assertions.assertThrows(ResponseStatusException.class, () -> gapsSearch.run(), "Should throw exception that the title was missing from the video element"); } - - @Test - void validGuidFromPlex() throws Exception { - gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.PLEX_WITH_GUID_URL); - - List movieUrls = new ArrayList<>(); - movieUrls.add(GapsUrlGeneratorTest.PLEX_WITH_GUID_URL); - - gapsSearch.run(); - assertEquals(gapsSearch.getTotalMovieCount(), 1, "Should have found exactly one movie"); - } - - @Test - void validYearXmlFromPlex() throws Exception { - gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.PLEX_MOVIE_URL); - - List movieUrls = new ArrayList<>(); - movieUrls.add(GapsUrlGeneratorTest.PLEX_MOVIE_URL); - gapsSearch.run(); - assertEquals(gapsSearch.getTotalMovieCount(), 1, "Should have found exactly one movie"); - } - -/* @Test - void invalidMovieDbFromPlex() throws Exception { - gapsUrlGeneratorTest.generatePlexUrl(GapsUrlGeneratorTest.PLEX_MOVIE_URL); - - List movieUrls = new ArrayList<>(); - movieUrls.add(GapsUrlGeneratorTest.PLEX_MOVIE_URL); - - gaps.setMovieUrls(movieUrls); - gaps.setSearchFromPlex(true); - gaps.setMovieDbApiKey("fake_id"); - gaps.setWriteToFile(false); - - gapsSearch.run(gaps, new ArrayList<>()); - assertEquals(gapsSearch.getRecommendedMovies().size(), 3, "Should have found exactly three movies recommended"); - }*/ - } \ No newline at end of file diff --git a/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsServiceTest.java b/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsServiceTest.java new file mode 100644 index 0000000..b40bc6a --- /dev/null +++ b/GapsWeb/src/test/java/com/jasonhhouse/gaps/GapsServiceTest.java @@ -0,0 +1,40 @@ +package com.jasonhhouse.gaps; + +import java.util.ArrayList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class GapsServiceTest implements GapsService { + + private PlexSearch plexSearch; + + public GapsServiceTest() { + plexSearch = new PlexSearch(); + plexSearch.setPlexToken("token"); + plexSearch.setPort(1); + plexSearch.setAddress("abc"); + plexSearch.setMovieDbApiKey("key"); + + PlexLibrary plexLibrary = new PlexLibrary(1, "Movies", true); + PlexLibrary plexLibrary1 = new PlexLibrary(2, "Movies HD", false); + List plexLibraries = new ArrayList<>(); + plexLibraries.add(plexLibrary); + plexLibraries.add(plexLibrary1); + plexSearch.getLibraries().addAll(plexLibraries); + } + + @Override + public PlexSearch getPlexSearch() { + return plexSearch; + } + + @Override + public void updateLibrarySelections(@NotNull List plexLibraries) { + + } + + @Override + public void updatePlexSearch(PlexSearch plexSearch) { + + } +} diff --git a/pom.xml b/pom.xml index 900c9b0..17893df 100644 --- a/pom.xml +++ b/pom.xml @@ -23,4 +23,39 @@ 1.8 + + + + org.apache.commons + commons-lang3 + 3.9 + + + + org.apache.commons + commons-collections4 + 4.4 + + + + com.squareup.okhttp3 + okhttp + 4.2.0 + + + + org.hibernate.validator + hibernate-validator + 6.0.18.Final + compile + + + + org.jetbrains + annotations + 17.0.0 + + + +