Minor - fix some small todo's
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.register;
|
||||
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
@@ -10,7 +9,6 @@ import fr.xephi.authme.process.register.RegistrationType;
|
||||
import fr.xephi.authme.process.register.executors.EmailRegisterParams;
|
||||
import fr.xephi.authme.process.register.executors.PasswordRegisterParams;
|
||||
import fr.xephi.authme.process.register.executors.RegistrationMethod;
|
||||
import fr.xephi.authme.process.register.executors.RegistrationParameters;
|
||||
import fr.xephi.authme.process.register.executors.TwoFactorRegisterParams;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
@@ -20,9 +18,6 @@ import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -31,16 +26,11 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static fr.xephi.authme.IsEqualByReflectionMatcher.isEqualTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -306,56 +296,4 @@ public class RegisterCommandTest {
|
||||
verify(management).performRegister(eq(RegistrationMethod.PASSWORD_REGISTRATION),
|
||||
argThat(isEqualTo(PasswordRegisterParams.of(player, "myPass", null))));
|
||||
}
|
||||
|
||||
|
||||
// TODO ljacqu 20170317: Document and extract as util
|
||||
|
||||
private static <P extends RegistrationParameters> Matcher<P> isEqualTo(P expected) {
|
||||
return new TypeSafeMatcher<P>() {
|
||||
@Override
|
||||
protected boolean matchesSafely(RegistrationParameters item) {
|
||||
assertAreParamsEqual(expected, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("parameters " + expected);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void assertAreParamsEqual(RegistrationParameters lhs, RegistrationParameters rhs) {
|
||||
if (lhs.getClass() != rhs.getClass()) {
|
||||
fail("Params classes don't match, got " + lhs.getClass().getSimpleName()
|
||||
+ " and " + rhs.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
List<Field> fieldsToCheck = getFields(lhs);
|
||||
for (Field field : fieldsToCheck) {
|
||||
Object lhsValue = ReflectionTestUtils.getFieldValue(field, lhs);
|
||||
Object rhsValue = ReflectionTestUtils.getFieldValue(field, rhs);
|
||||
if (!Objects.equals(lhsValue, rhsValue)) {
|
||||
fail("Field '" + field.getName() + "' does not have same value: '"
|
||||
+ lhsValue + "' vs. '" + rhsValue + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Field> getFields(RegistrationParameters params) {
|
||||
List<Field> fields = new ArrayList<>();
|
||||
Class<?> currentClass = params.getClass();
|
||||
while (currentClass != null) {
|
||||
for (Field f : currentClass.getDeclaredFields()) {
|
||||
if (!Modifier.isStatic(f.getModifiers())) {
|
||||
fields.add(f);
|
||||
}
|
||||
}
|
||||
if (currentClass == RegistrationParameters.class) {
|
||||
break;
|
||||
}
|
||||
currentClass = currentClass.getSuperclass();
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user