/*
- * Sone - MemoryDatabaseTest.java - Copyright © 2013–2016 David Roden
+ * Sone - MemoryDatabaseTest.java - Copyright © 2013–2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* Tests for {@link MemoryDatabase}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public class MemoryDatabaseTest {
.withTime(4000L)
.withText("reply2")
.build();
- Set<PostReply> postReplies = new HashSet<PostReply>(
+ Set<PostReply> postReplies = new HashSet<>(
asList(firstPostFirstReply, firstPostSecondReply,
secondPostReply));
when(sone.getReplies()).thenReturn(postReplies);
"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);
@Test
public void storedAndRemovedSoneIsNotAvailable() {
- storedSoneIsMadeAvailable();
+ storedSoneIsMadeAvailable();
memoryDatabase.removeSone(sone);
assertThat(memoryDatabase.getSones(), empty());
}
}
@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);
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));
+ }
+
}