ChatFilterPlugin extends Plugin { boolean shouldFilterPlayerMessage(String playerName) { boolean isMessageFromSelf = playerName.equals(client.getLocalPlayer().getName()); return !isMessageFromSelf && (config.filterFriends() || !client.isFriended(playerName, false)) && (config.filterFriendsChat() || !friendChatManager.isMember(playerName)); }  @Subscribe void onScriptCallbackEvent(ScriptCallbackEvent event); @Subscribe void onOverheadTextChanged(OverheadTextChanged event); @Subscribe(priority = -2) // run after ChatMessageManager void onChatMessage(ChatMessage chatMessage); @Subscribe void onConfigChanged(ConfigChanged event);  }
@Test public void testMessageFromFriendIsFiltered() { when(friendChatManager.isMember("Iron Mammal")).thenReturn(false); when(chatFilterConfig.filterFriends()).thenReturn(true); assertTrue(chatFilterPlugin.shouldFilterPlayerMessage("Iron Mammal")); }
@Test public void testMessageFromFriendIsNotFiltered() { when(client.isFriended("Iron Mammal", false)).thenReturn(true); when(chatFilterConfig.filterFriends()).thenReturn(false); assertFalse(chatFilterPlugin.shouldFilterPlayerMessage("Iron Mammal")); }
@Test public void testMessageFromFriendsChatIsFiltered() { when(client.isFriended("B0aty", false)).thenReturn(false); when(chatFilterConfig.filterFriendsChat()).thenReturn(true); assertTrue(chatFilterPlugin.shouldFilterPlayerMessage("B0aty")); }
@Test public void testMessageFromFriendsChatIsNotFiltered() { when(friendChatManager.isMember("B0aty")).thenReturn(true); when(chatFilterConfig.filterFriendsChat()).thenReturn(false); assertFalse(chatFilterPlugin.shouldFilterPlayerMessage("B0aty")); }
@Test public void testMessageFromSelfIsNotFiltered() { when(localPlayer.getName()).thenReturn("Swampletics"); assertFalse(chatFilterPlugin.shouldFilterPlayerMessage("Swampletics")); }
@Test public void testMessageFromNonFriendNonFCIsFiltered() { when(client.isFriended("Woox", false)).thenReturn(false); when(friendChatManager.isMember("Woox")).thenReturn(false); assertTrue(chatFilterPlugin.shouldFilterPlayerMessage("Woox")); }