Merge "stringWithLength" matcher implementations

- For some reason Hamcrest does not provide a "string with length" matcher -> move our two implementations as one method in AuthMe matchers class
This commit is contained in:
ljacqu 2016-07-22 22:14:10 +02:00
parent 914462fc3f
commit cf3d84e3c1
3 changed files with 16 additions and 35 deletions

View File

@ -81,4 +81,18 @@ public final class AuthMeMatchers {
};
}
public static Matcher<String> stringWithLength(final int length) {
return new TypeSafeMatcher<String>() {
@Override
protected boolean matchesSafely(String item) {
return item != null && item.length() == length;
}
@Override
public void describeTo(Description description) {
description.appendText("String with length " + length);
}
};
}
}

View File

@ -11,9 +11,6 @@ import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.properties.EmailSettings;
import org.bukkit.entity.Player;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -25,6 +22,7 @@ import org.mockito.stubbing.Answer;
import java.util.Collections;
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
@ -199,19 +197,4 @@ public class RecoverEmailCommandTest {
.build();
}
private static Matcher<String> stringWithLength(final int length) {
return new TypeSafeMatcher<String>() {
@Override
public void describeTo(Description description) {
description.appendText("String of length " + length);
}
@Override
protected boolean matchesSafely(String s) {
return s.length() == length;
}
};
}
}

View File

@ -13,8 +13,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.TypeSafeMatcher;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -27,6 +25,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
@ -241,19 +240,4 @@ public class RegisterCommandTest {
// then
verify(management).performRegister(player, "myPass", "", true);
}
private static TypeSafeMatcher<String> stringWithLength(final int length) {
return new TypeSafeMatcher<String>() {
@Override
protected boolean matchesSafely(String item) {
return item != null && item.length() == length;
}
@Override
public void describeTo(Description description) {
description.appendText("String with length " + length);
}
};
}
}