Various code householding
- Remove unused API on DataSource - Add some sensible javadoc to DataSource - Minor code simplification
This commit is contained in:
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -48,8 +47,8 @@ public class AccountsCommandTest {
|
||||
// given
|
||||
given(sender.getName()).willReturn("Tester");
|
||||
List<String> arguments = Collections.EMPTY_LIST;
|
||||
given(dataSource.getAuth("tester")).willReturn(mock(PlayerAuth.class));
|
||||
given(dataSource.getAllAuthsByName(any(PlayerAuth.class))).willReturn(Arrays.asList("Toaster", "Pester"));
|
||||
given(dataSource.getAuth("tester")).willReturn(authWithIp("123.45.67.89"));
|
||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Arrays.asList("Toaster", "Pester"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
@@ -81,7 +80,7 @@ public class AccountsCommandTest {
|
||||
// given
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
|
||||
given(dataSource.getAllAuthsByName(any(PlayerAuth.class))).willReturn(Collections.EMPTY_LIST);
|
||||
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.EMPTY_LIST);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
@@ -96,8 +95,8 @@ public class AccountsCommandTest {
|
||||
public void shouldReturnSingleAccountMessage() {
|
||||
// given
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
|
||||
given(dataSource.getAllAuthsByName(any(PlayerAuth.class))).willReturn(Collections.singletonList("SomeUser"));
|
||||
given(dataSource.getAuth("someuser")).willReturn(authWithIp("56.78.90.123"));
|
||||
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
@@ -169,4 +168,11 @@ public class AccountsCommandTest {
|
||||
verify(sender, times(expectedCount)).sendMessage(captor.capture());
|
||||
return captor.getAllValues().toArray(new String[expectedCount]);
|
||||
}
|
||||
|
||||
private static PlayerAuth authWithIp(String ip) {
|
||||
return PlayerAuth.builder()
|
||||
.name("Test")
|
||||
.ip(ip)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import fr.xephi.authme.settings.properties.TestConfiguration;
|
||||
import fr.xephi.authme.settings.properties.TestEnum;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -32,10 +31,10 @@ public class NewSettingTest {
|
||||
public void shouldLoadAllConfigs() {
|
||||
// given
|
||||
YamlConfiguration configuration = mock(YamlConfiguration.class);
|
||||
given(configuration.getString(anyString(), anyString())).willAnswer(withDefaultArgument());
|
||||
given(configuration.getBoolean(anyString(), anyBoolean())).willAnswer(withDefaultArgument());
|
||||
given(configuration.getDouble(anyString(), anyDouble())).willAnswer(withDefaultArgument());
|
||||
given(configuration.getInt(anyString(), anyInt())).willAnswer(withDefaultArgument());
|
||||
given(configuration.getString(anyString(), anyString())).willAnswer(new ReturnsArgumentAt(1));
|
||||
given(configuration.getBoolean(anyString(), anyBoolean())).willAnswer(new ReturnsArgumentAt(1));
|
||||
given(configuration.getDouble(anyString(), anyDouble())).willAnswer(new ReturnsArgumentAt(1));
|
||||
given(configuration.getInt(anyString(), anyInt())).willAnswer(new ReturnsArgumentAt(1));
|
||||
|
||||
setReturnValue(configuration, TestConfiguration.VERSION_NUMBER, 20);
|
||||
setReturnValue(configuration, TestConfiguration.SKIP_BORING_FEATURES, true);
|
||||
@@ -89,14 +88,4 @@ public class NewSettingTest {
|
||||
setting.getProperty(property).equals(property.getDefaultValue()), equalTo(true));
|
||||
}
|
||||
|
||||
private static <T> Answer<T> withDefaultArgument() {
|
||||
return new Answer<T>() {
|
||||
@Override
|
||||
public T answer(InvocationOnMock invocation) throws Throwable {
|
||||
// Return the second parameter -> the default
|
||||
return (T) invocation.getArguments()[1];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user