From fe8007a65255a103bd7f2990243aabc38f383202 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 25 Nov 2014 21:48:55 +0100 Subject: [PATCH] Load friends before modifying them. --- .../net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java | 2 ++ .../net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) 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()); } } -- 2.7.4