Load friends before modifying them.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 25 Nov 2014 20:48:55 +0000 (21:48 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 25 Nov 2014 20:48:55 +0000 (21:48 +0100)
src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java

index 1802843..0be8738 100644 (file)
@@ -43,6 +43,7 @@ class MemoryFriendDatabase {
        }
 
        void addFriend(String localSoneId, String friendSoneId) {
+               loadFriends(localSoneId);
                lock.writeLock().lock();
                try {
                        if (soneFriends.put(localSoneId, friendSoneId)) {
@@ -54,6 +55,7 @@ class MemoryFriendDatabase {
        }
 
        void removeFriend(String localSoneId, String friendSoneId) {
+               loadFriends(localSoneId);
                lock.writeLock().lock();
                try {
                        if (soneFriends.remove(localSoneId, friendSoneId)) {
index ac23a81..cc5babb 100644 (file)
@@ -363,7 +363,7 @@ public class MemoryDatabaseTest {
                when(sone.isLocal()).thenReturn(true);
                memoryDatabase.addFriend(sone, "Friend1");
                memoryDatabase.addFriend(sone, "Friend1");
-               verify(configuration, times(2)).getStringValue(anyString());
+               verify(configuration, times(3)).getStringValue(anyString());
        }
 
        @Test
@@ -380,9 +380,10 @@ public class MemoryDatabaseTest {
 
        @Test
        public void configurationIsNotWrittenWhenANonFriendIsRemoved() {
+               prepareConfigurationValues();
                when(sone.isLocal()).thenReturn(true);
                memoryDatabase.removeFriend(sone, "Friend1");
-               verify(configuration, never()).getStringValue(anyString());
+               verify(configuration).getStringValue(anyString());
        }
 
 }