Minor test adjustments

This commit is contained in:
ljacqu 2016-02-21 20:23:36 +01:00
parent 1afe41d787
commit 203e954eea
3 changed files with 27 additions and 41 deletions

View File

@ -2,9 +2,9 @@ package fr.xephi.authme.datasource;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.security.crypts.HashedPassword;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import java.util.Objects;
@ -21,14 +21,10 @@ public final class AuthMeMatchers {
}
public static Matcher<? super HashedPassword> equalToHash(final String hash, final String salt) {
return new BaseMatcher<HashedPassword>() {
return new TypeSafeMatcher<HashedPassword>() {
@Override
public boolean matches(Object item) {
if (item instanceof HashedPassword) {
HashedPassword input = (HashedPassword) item;
return Objects.equals(hash, input.getHash()) && Objects.equals(salt, input.getSalt());
}
return false;
public boolean matchesSafely(HashedPassword item) {
return Objects.equals(hash, item.getHash()) && Objects.equals(salt, item.getSalt());
}
@Override
@ -44,17 +40,13 @@ public final class AuthMeMatchers {
public static Matcher<? super PlayerAuth> hasAuthBasicData(final String name, final String realName,
final String email, final String ip) {
return new BaseMatcher<PlayerAuth>() {
return new TypeSafeMatcher<PlayerAuth>() {
@Override
public boolean matches(Object item) {
if (item instanceof PlayerAuth) {
PlayerAuth input = (PlayerAuth) item;
return Objects.equals(name, input.getNickname())
&& Objects.equals(realName, input.getRealName())
&& Objects.equals(email, input.getEmail())
&& Objects.equals(ip, input.getIp());
}
return false;
public boolean matchesSafely(PlayerAuth item) {
return Objects.equals(name, item.getNickname())
&& Objects.equals(realName, item.getRealName())
&& Objects.equals(email, item.getEmail())
&& Objects.equals(ip, item.getIp());
}
@Override
@ -67,17 +59,13 @@ public final class AuthMeMatchers {
public static Matcher<? super PlayerAuth> hasAuthLocation(final double x, final double y, final double z,
final String world) {
return new BaseMatcher<PlayerAuth>() {
return new TypeSafeMatcher<PlayerAuth>() {
@Override
public boolean matches(Object item) {
if (item instanceof PlayerAuth) {
PlayerAuth input = (PlayerAuth) item;
return Objects.equals(x, input.getQuitLocX())
&& Objects.equals(y, input.getQuitLocY())
&& Objects.equals(z, input.getQuitLocZ())
&& Objects.equals(world, input.getWorld());
}
return false;
public boolean matchesSafely(PlayerAuth item) {
return Objects.equals(x, item.getQuitLocX())
&& Objects.equals(y, item.getQuitLocY())
&& Objects.equals(z, item.getQuitLocZ())
&& Objects.equals(world, item.getWorld());
}
@Override

View File

@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
*/
public class SQLiteIntegrationTest {
/** Mock for a settings instance. */
/** Mock of a settings instance. */
private static NewSetting settings;
/** Collection of SQL statements to execute for initialization of a test. */
private static String[] sqlInitialize;
@ -70,7 +70,7 @@ public class SQLiteIntegrationTest {
}
@Before
public void initializeConnectionAndTable() throws SQLException, ClassNotFoundException {
public void initializeConnectionAndTable() throws SQLException {
silentClose(con);
Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:");
try (Statement st = connection.createStatement()) {
@ -88,14 +88,14 @@ public class SQLiteIntegrationTest {
DataSource dataSource = new SQLite(settings, con, false);
// when
boolean bobby = dataSource.isAuthAvailable("bobby");
boolean chris = dataSource.isAuthAvailable("chris");
boolean user = dataSource.isAuthAvailable("USER");
boolean isBobbyAvailable = dataSource.isAuthAvailable("bobby");
boolean isChrisAvailable = dataSource.isAuthAvailable("chris");
boolean isUserAvailable = dataSource.isAuthAvailable("USER");
// then
assertThat(bobby, equalTo(true));
assertThat(chris, equalTo(false));
assertThat(user, equalTo(true));
assertThat(isBobbyAvailable, equalTo(true));
assertThat(isChrisAvailable, equalTo(false));
assertThat(isUserAvailable, equalTo(true));
}
@Test
@ -109,8 +109,7 @@ public class SQLiteIntegrationTest {
HashedPassword userPassword = dataSource.getPassword("user");
// then
assertThat(bobbyPassword, equalToHash(
"$SHA$11aa0706173d7272$dbba96681c2ae4e0bfdf226d70fbbc5e4ee3d8071faa613bc533fe8a64817d10"));
assertThat(bobbyPassword, equalToHash("$SHA$11aa0706173d7272$dbba966"));
assertThat(invalidPassword, nullValue());
assertThat(userPassword, equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
}
@ -131,8 +130,7 @@ public class SQLiteIntegrationTest {
assertThat(bobbyAuth, hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89"));
assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world"));
assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L));
assertThat(bobbyAuth.getPassword(), equalToHash(
"$SHA$11aa0706173d7272$dbba96681c2ae4e0bfdf226d70fbbc5e4ee3d8071faa613bc533fe8a64817d10"));
assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90"));
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether"));

View File

@ -17,6 +17,6 @@ CREATE TABLE authme (
);
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt)
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba96681c2ae4e0bfdf226d70fbbc5e4ee3d8071faa613bc533fe8a64817d10','123.45.67.89',1449136800,1.05,2.1,4.2,'world','your@email.com',0,'Bobby',NULL);
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world','your@email.com',0,'Bobby',NULL);
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt)
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether','user@example.org',0,'user','f750ba32');