Cleaning up possible null pointer

Cleaning up tests
Cleaning up poms
This commit is contained in:
jhouse
2020-01-06 10:06:34 +09:00
parent 30a00beacf
commit ecb7f6b7de
7 changed files with 80 additions and 130 deletions
-6
View File
@@ -15,32 +15,26 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>17.0.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.18.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
-5
View File
@@ -85,19 +85,16 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
@@ -109,7 +106,6 @@
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<dependency>
@@ -127,7 +123,6 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>17.0.0</version>
</dependency>
<dependency>
@@ -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");
}
+1 -1
View File
@@ -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
@@ -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<Movie> 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<PlexLibrary> 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<String> 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<String> movieUrls = new ArrayList<>();
movieUrls.add(GapsUrlGeneratorTest.NO_MOVIE_PLEX_URL);
gapsSearch.run();
List<Movie> 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<String> 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<String> 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<String> 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<String> 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");
}*/
}
@@ -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<PlexLibrary> 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<PlexLibrary> plexLibraries) {
}
@Override
public void updatePlexSearch(PlexSearch plexSearch) {
}
}
+35
View File
@@ -23,4 +23,39 @@
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.18.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>17.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>