This commit is contained in:
DNx5 2016-04-01 13:47:35 +07:00
parent c63b9786f8
commit 46a10da40f

View File

@ -18,36 +18,10 @@ import static org.mockito.Mockito.mock;
*/ */
public class IpAddressManagerTest { public class IpAddressManagerTest {
@Test private static NewSetting mockSettings(boolean useVeryGames, boolean useBungee) {
public void shouldRetrieveFromCache() {
// given
IpAddressManager ipAddressManager = new IpAddressManager(mockSettings(true));
ipAddressManager.addCache("Test", "my test IP");
// when
String result = ipAddressManager.getPlayerIp(mockPlayer("test", "123.123.123.123"));
// then
assertThat(result, equalTo("my test IP"));
}
@Test
public void shouldReturnPlainIp() {
// given
IpAddressManager ipAddressManager = new IpAddressManager(mockSettings(false));
// when
String result = ipAddressManager.getPlayerIp(mockPlayer("bobby", "8.8.8.8"));
// then
assertThat(result, equalTo("8.8.8.8"));
}
private static NewSetting mockSettings(boolean useVeryGames) {
NewSetting settings = mock(NewSetting.class); NewSetting settings = mock(NewSetting.class);
given(settings.getProperty(HooksSettings.ENABLE_VERYGAMES_IP_CHECK)).willReturn(useVeryGames); given(settings.getProperty(HooksSettings.ENABLE_VERYGAMES_IP_CHECK)).willReturn(useVeryGames);
given(settings.getProperty(HooksSettings.BUNGEECORD)).willReturn(useBungee);
return settings; return settings;
} }
@ -61,4 +35,29 @@ public class IpAddressManagerTest {
return player; return player;
} }
@Test
public void shouldRetrieveFromCache() {
// given
IpAddressManager ipAddressManager = new IpAddressManager(mockSettings(true, true));
ipAddressManager.addCache("Test", "my test IP");
// when
String result = ipAddressManager.getPlayerIp(mockPlayer("test", "123.123.123.123"));
// then
assertThat(result, equalTo("my test IP"));
}
@Test
public void shouldReturnPlainIp() {
// given
IpAddressManager ipAddressManager = new IpAddressManager(mockSettings(false, false));
// when
String result = ipAddressManager.getPlayerIp(mockPlayer("bobby", "8.8.8.8"));
// then
assertThat(result, equalTo("8.8.8.8"));
}
} }