X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FMemoryDatabaseTest.java;h=d5c6ead4292937641dcf92b93a7d159e7c0fe39b;hp=47c2c4c3a36c5858fa8079acebff6d33918dcfdc;hb=9fc45be4cce92e2d960395a35d046b2c5808a0bb;hpb=7804921fddbc1a9c7e6c739e802b724b45190cc8 diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index 47c2c4c..d5c6ead 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -141,6 +141,7 @@ public class MemoryDatabaseTest { "album-description3").update(); firstAlbum.addAlbum(thirdAlbum); Album rootAlbum = mock(Album.class); + when(rootAlbum.getId()).thenReturn("root"); when(rootAlbum.getAlbums()).thenReturn( asList(firstAlbum, secondAlbum)); when(sone.getRootAlbum()).thenReturn(rootAlbum); @@ -215,7 +216,7 @@ public class MemoryDatabaseTest { @Test public void storedAndRemovedSoneIsNotAvailable() { - storedSoneIsMadeAvailable(); + storedSoneIsMadeAvailable(); memoryDatabase.removeSone(sone); assertThat(memoryDatabase.getSones(), empty()); } @@ -392,6 +393,22 @@ public class MemoryDatabaseTest { } @Test + public void soneFollowingTimeIsReturnedCorrectly() throws ConfigurationException { + prepareConfigurationValues(); + configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("sone"); + configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L); + assertThat(memoryDatabase.getFollowingTime("sone"), equalTo(1000L)); + } + + @Test + public void nullisReturnedWhenSoneIsNotFollowed() throws ConfigurationException { + prepareConfigurationValues(); + configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("otherSone"); + configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L); + assertThat(memoryDatabase.getFollowingTime("sone"), nullValue()); + } + + @Test public void timeIsStoredInConfigurationWhenASoneIsFollowed() throws ConfigurationException { prepareConfigurationValues(); when(sone.isLocal()).thenReturn(true); @@ -413,4 +430,32 @@ public class MemoryDatabaseTest { assertThat(configuration.getStringValue("SoneFollowingTimes/1/Sone").getValue(), nullValue()); } + @Test + public void unfollowingASoneRemovesTheFollowingTime() throws ConfigurationException { + prepareConfigurationValues(); + configuration.getStringValue("Sone/sone/Friends/0/ID").setValue("Friend"); + configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("Friend"); + configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L); + when(sone.isLocal()).thenReturn(true); + memoryDatabase.removeFriend(sone, "Friend"); + assertThat(configuration.getStringValue("SoneFollowingTimes/0/Sone").getValue(), nullValue()); + } + + @Test + public void unfollowingASoneDoesNotRemoveTheFollowingTimeIfAnotherLocalSoneFollowsIt() throws ConfigurationException { + prepareConfigurationValues(); + configuration.getStringValue("Sone/sone/Friends/0/ID").setValue("Friend"); + configuration.getStringValue("Sone/other-sone/Friends/0/ID").setValue("Friend"); + configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("Friend"); + configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L); + Sone otherSone = mock(Sone.class); + when(otherSone.isLocal()).thenReturn(true); + when(otherSone.getId()).thenReturn("other-sone"); + memoryDatabase.getFriends(otherSone); + when(sone.isLocal()).thenReturn(true); + memoryDatabase.removeFriend(sone, "Friend"); + assertThat(configuration.getStringValue("SoneFollowingTimes/0/Sone").getValue(), equalTo("Friend")); + assertThat(configuration.getLongValue("SoneFollowingTimes/0/Time").getValue(), equalTo(1000L)); + } + }