More test coverage

This commit is contained in:
Jason House
2020-06-05 09:48:51 +09:00
parent 29a34da25e
commit ff6f353689
7 changed files with 214 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
package com.jasonhhouse.gaps;
import java.util.Objects;
public class Pair<L,R> {
private final L left;
private final R right;
@@ -17,6 +19,20 @@ public class Pair<L,R> {
return right;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(left, pair.left) &&
Objects.equals(right, pair.right);
}
@Override
public int hashCode() {
return Objects.hash(left, right);
}
@Override
public String toString() {
return "Pair{" +

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2020 Jason H House
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.jasonhhouse.gaps;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class PairTest {
@Test
void pairTest() {
Pair<Integer, Float> pair1 = new Pair<>(1, 1.0F);
Pair<Integer, Float> pair2 = new Pair<>(1, 1.0F);
Pair<Integer, Float> pair3 = new Pair<>(1, 2.0F);
assertEquals(pair1.getLeft(), pair2.getLeft(), "Pair1 and Pair2 left should match");
assertEquals(pair1.getRight(), pair2.getRight(), "Pair1 and Pair2 right should match");
assertEquals(pair1, pair2, "Pair equals method broken");
assertNotEquals(pair1, pair3, "Pair equals method broken");
}
}

View File

@@ -84,7 +84,7 @@
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.4.1-1</version>
<version>4.5.0</version>
</dependency>
<dependency>
@@ -128,7 +128,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<version>2.7</version>
</dependency>
<dependency>
@@ -220,17 +220,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<version>2.22.2</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<version>5.7.0-M1</version>
</dependency>
</dependencies>
</plugin>

View File

@@ -35,5 +35,34 @@
<artifactId>jaxb-impl</artifactId>
<version>${jaxb.api.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- exclude junit 4 -->
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2020 Jason H House
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.jasonhhouse.plex;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class PlexTest {
@Test
void PlexObjectsTest() {
MediaContainer mediaContainer;
try {
String xml = IOUtils.toString(this.getClass().getResourceAsStream("plex_videos.xml"), StandardCharsets.UTF_8);
InputStream inputStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
JAXBContext jaxbContext = JAXBContext.newInstance(MediaContainer.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
mediaContainer = (MediaContainer) jaxbUnmarshaller.unmarshal(inputStream);
assertEquals(mediaContainer.getVideos().size(), 3, "Should find three videos");
} catch (IOException e) {
fail("Failed to read plex videos xml file");
} catch (JAXBException e) {
fail("Failed to parse plex videos xml file");
}
}
}

View File

@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="3" allowSync="1" art="/:/resources/movie-fanart.jpg" identifier="com.plexapp.plugins.library"
librarySectionID="1" librarySectionTitle="Movies"
librarySectionUUID="c3337a1d-6053-4807-85e2-7bb3f00131e7" mediaTagPrefix="/system/bundle/media/flags/"
mediaTagVersion="1590435351" thumb="/:/resources/movie.png" title1="Movies" title2="All Movies"
viewGroup="movie" viewMode="65592">
<Video ratingKey="1" key="/library/metadata/1" guid="com.plexapp.agents.imdb://tt0240772?lang=en"
studio="Village Roadshow Pictures" type="movie" title="Ocean's Eleven" contentRating="PG-13"
summary="Less than 24 hours into his parole, charismatic thief Danny Ocean is already rolling out his next plan: In one night, Danny's hand-picked crew of specialists will attempt to steal more than $150 million from three Las Vegas casinos. But to score the cash, Danny risks his chances of reconciling with ex-wife, Tess."
rating="8.2" audienceRating="8.0" year="2001" tagline="Are you in or out?"
thumb="/library/metadata/1/thumb/1581512603" art="/library/metadata/1/art/1581512603" duration="6994208"
originallyAvailableAt="2001-12-07" addedAt="1516381009" updatedAt="1581512603"
audienceRatingImage="rottentomatoes://image.rating.upright" chapterSource="media"
primaryExtraKey="/library/metadata/6" ratingImage="rottentomatoes://image.rating.ripe">
<Media id="1" duration="6994208" bitrate="19121" width="1920" height="1080" aspectRatio="1.78" audioChannels="6"
audioCodec="ac3" videoCodec="vc1" videoResolution="1080" container="mkv" videoFrameRate="24p"
videoProfile="advanced">
<Part id="1" key="/library/parts/1/1516381009/file.mkv" duration="6994208"
file="/media/Movies/Ocean's Eleven (2001)/Ocean's Eleven (2001).mkv" size="16719234483"
container="mkv" videoProfile="advanced"/>
</Media>
<Genre tag="Crime"/>
<Genre tag="Thriller"/>
<Director tag="Steven Soderbergh"/>
<Writer tag="George Clayton Johnson"/>
<Writer tag="Ted Griffin"/>
<Country tag="USA"/>
<Role tag="George Clooney"/>
<Role tag="Brad Pitt"/>
<Role tag="Matt Damon"/>
</Video>
<Video ratingKey="2" key="/library/metadata/2" guid="com.plexapp.agents.imdb://tt0132477?lang=en"
studio="Universal Pictures" type="movie" title="October Sky" contentRating="PG"
summary="Based on the true story of Homer Hickam, a coal miner's son who was inspired by the first Sputnik launch to take up rocketry against his father's wishes, and eventually became a NASA scientist."
rating="9.1" audienceRating="8.8" year="1999"
tagline="Sometimes one dream is enough to light up the whole sky."
thumb="/library/metadata/2/thumb/1581512602" art="/library/metadata/2/art/1581512602" duration="6174880"
originallyAvailableAt="1999-02-19" addedAt="1516379035" updatedAt="1581512602"
audienceRatingImage="rottentomatoes://image.rating.upright" primaryExtraKey="/library/metadata/5"
ratingImage="rottentomatoes://image.rating.ripe">
<Media id="2" duration="6174880" bitrate="6074" width="1280" height="544" aspectRatio="2.35" audioChannels="6"
audioCodec="ac3" videoCodec="h264" videoResolution="720" container="mkv" videoFrameRate="PAL"
videoProfile="high">
<Part id="2" key="/library/parts/2/1516379035/file.mkv" duration="6174880"
file="/media/Movies/October Sky (1999)/October Sky (1999).mkv" size="4691611116" container="mkv"
videoProfile="high"/>
</Media>
<Genre tag="Biography"/>
<Genre tag="Drama"/>
<Director tag="Joe Johnston"/>
<Writer tag="Lewis Colick"/>
<Country tag="USA"/>
<Role tag="Jake Gyllenhaal"/>
<Role tag="Chris Cooper"/>
<Role tag="Laura Dern"/>
</Video>
<Video ratingKey="3" key="/library/metadata/3" guid="com.plexapp.agents.imdb://tt0325980?lang=en"
studio="Walt Disney Pictures" type="movie" title="Pirates of the Caribbean: The Curse of the Black Pearl"
contentRating="PG-13"
summary="Jack Sparrow, a freewheeling 18th-century pirate, quarrels with a rival pirate bent on pillaging Port Royal. When the governor's daughter is kidnapped, Sparrow decides to help the girl's love save her."
rating="7.9" audienceRating="8.6" year="2003" tagline="Prepare to be blown out of the water."
thumb="/library/metadata/3/thumb/1581512607" art="/library/metadata/3/art/1581512607" duration="8590592"
originallyAvailableAt="2003-07-09" addedAt="1516381620" updatedAt="1581512607"
audienceRatingImage="rottentomatoes://image.rating.upright" primaryExtraKey="/library/metadata/27"
ratingImage="rottentomatoes://image.rating.ripe">
<Media id="3" duration="8590592" bitrate="18385" width="1920" height="816" aspectRatio="2.35" audioChannels="6"
audioCodec="ac3" videoCodec="h264" videoResolution="1080" container="mkv" videoFrameRate="24p"
videoProfile="high">
<Part id="3" key="/library/parts/3/1516381620/file.mkv" duration="8590592"
file="/media/Movies/Pirates of the Caribbean The Curse of the Black Pearl (2003)/Pirates of the Caribbean The Curse of the Black Pearl (2003).mkv"
size="19746755684" container="mkv" videoProfile="high"/>
</Media>
<Genre tag="Action"/>
<Genre tag="Adventure"/>
<Director tag="Gore Verbinski"/>
<Writer tag="Ted Elliott"/>
<Writer tag="Terry Rossio"/>
<Country tag="USA"/>
<Role tag="Johnny Depp"/>
<Role tag="Geoffrey Rush"/>
<Role tag="Orlando Bloom"/>
</Video>
</MediaContainer>

View File

@@ -102,7 +102,7 @@
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>4.0.2</version>
<version>4.0.3</version>
</dependency>
</dependencies>
</plugin>