This repository has been archived by the owner on Feb 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase model and database test coverage (#87)
* edit follow test * Revert "edit follow test" This reverts commit 4adee47. * Add get following and followers test * remove generic database * Add collection model tests * Add dates test
- Loading branch information
1 parent
8f0277f
commit 775b719
Showing
6 changed files
with
108 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
app/src/main/java/com/github/sdp/mediato/data/GenericDatabase.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
app/src/test/java/com/github/sdp/mediato/ExampleUnitTest.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
app/src/test/java/com/github/sdp/mediato/formats/DatesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.sdp.mediato.formats; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Date; | ||
|
||
public class DatesTests { | ||
|
||
@Test | ||
//Tests that the Dates class returns today's date with the right format | ||
public void getsTodaysDateProperly(){ | ||
LocalDate today = LocalDate.now(); | ||
String expected = pad(today.getDayOfMonth()) + "/" + pad(today.getMonthValue()) + "/" + today.getYear(); | ||
assertEquals(expected, Dates.getToday()); | ||
} | ||
|
||
//Adds leading zero to number | ||
public String pad(int number){ | ||
if(number < 10) return "0" + number; | ||
else return String.valueOf(number); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/test/java/com/github/sdp/mediato/model/CollectionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.github.sdp.mediato.model; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import com.github.sdp.mediato.model.media.Collection; | ||
import com.github.sdp.mediato.model.media.CollectionType; | ||
import com.github.sdp.mediato.model.media.Movie; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CollectionTests { | ||
private static Map<String, Review> reviews = new HashMap<>(); | ||
private static String SAMPLE_TITLE = "Harry Potter"; | ||
private static String SAMPLE_DESCRIPTION = "Description"; | ||
private static String SAMPLE_URL = "Url"; | ||
private static int SAMPLE_ID = 1; | ||
|
||
private static String SAMPLE_USERNAME = "testUser"; | ||
private static final Movie SAMPLE_MOVIE = new Movie(SAMPLE_TITLE , SAMPLE_DESCRIPTION, SAMPLE_URL, SAMPLE_ID); | ||
|
||
@BeforeClass | ||
public static void setUp(){ | ||
reviews.put(SAMPLE_TITLE, new Review(SAMPLE_USERNAME, SAMPLE_MOVIE)); | ||
} | ||
|
||
@Test | ||
//Tests that a custom collection is created properly | ||
public void createsCustomCollectionProperly(){ | ||
Collection collection = new Collection("MyCustom", reviews); | ||
assertThat(collection.getCollectionType(), is(CollectionType.CUSTOM)); | ||
assertThat(collection.getCollectionName(), is("MyCustom")); | ||
assertThat(CollectionType.CUSTOM.toString(), is("Custom")); | ||
} | ||
|
||
@Test | ||
//Tests that a favourites collection is created properly | ||
public void createsFavouriteCollectionProperly(){ | ||
Collection collection = new Collection(CollectionType.FAVOURITES, reviews); | ||
assertThat(collection.getCollectionType(), is(CollectionType.FAVOURITES)); | ||
assertThat(collection.getCollectionName(), is(CollectionType.FAVOURITES.toString())); | ||
} | ||
|
||
@Test | ||
//Tests that a recently watched collection is created properly | ||
public void createsRecentlyWatchedCollectionProperly(){ | ||
Collection collection = new Collection(CollectionType.RECENTLY_WATCHED, reviews); | ||
assertThat(collection.getCollectionType(), is(CollectionType.RECENTLY_WATCHED)); | ||
assertThat(collection.getCollectionName(), is(CollectionType.RECENTLY_WATCHED.toString())); | ||
} | ||
|
||
@Test | ||
//Tests that custom collection creation fails when the wrong constructor is used | ||
public void defaultCollectionConstructorFailsWhenTypeIsCustom(){ | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new Collection(CollectionType.CUSTOM, reviews) | ||
); | ||
} | ||
} |