From: David ‘Bombe’ Roden Date: Tue, 25 Nov 2014 20:48:55 +0000 (+0100) Subject: Load friends before modifying them. X-Git-Tag: 0.9-rc1^2~3^2~11 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fe8007a65255a103bd7f2990243aabc38f383202;p=Sone.git Load friends before modifying them. --- diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java index 1802843..0be8738 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java @@ -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)) { 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 ac23a81..cc5babb 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -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()); } }