Fix UtilsTest, create MessageKeyTest

This commit is contained in:
ljacqu 2015-11-24 22:21:36 +01:00
parent e4c82e04ff
commit 72fe710b8c
4 changed files with 57 additions and 3 deletions

View File

@ -34,6 +34,7 @@ public final class Utils {
static {
plugin = AuthMe.getInstance();
wrapper = new Wrapper(plugin);
initializeOnlinePlayersIsCollectionField();
}

View File

@ -0,0 +1,33 @@
package fr.xephi.authme.settings;
import fr.xephi.authme.util.StringUtils;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.fail;
/**
* Test for {@link MessageKey}.
*/
public class MessageKeyTest {
@Test
public void shouldHaveUniqueMessageKeys() {
// given
MessageKey[] messageKeys = MessageKey.values();
Set<String> keys = new HashSet<>();
// when / then
for (MessageKey messageKey : messageKeys) {
String key = messageKey.getKey();
if (keys.contains(key)) {
fail("Found key '" + messageKey.getKey() + "' twice!");
} else if (StringUtils.isEmpty(key)) {
fail("Key for message key '" + messageKey + "' is empty");
}
keys.add(key);
}
}
}

View File

@ -7,22 +7,38 @@ import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.net.URL;
import static java.util.Arrays.asList;
/**
* Test for {@link Messages}.
*/
public class MessagesTest {
private static final String YML_TEST_FILE = "messages_test.yml";
private Messages messages;
@Before
public void setUpMessages() {
AuthMe authMe = AuthMeMockUtil.mockAuthMeInstance();
AuthMeMockUtil.insertMockWrapperInstance(ConsoleLogger.class, "wrapper", authMe);
File file = new File("messages_test.yml");
Messages messages = new Messages(file, "en");
Settings.messagesLanguage = "en";
URL url = getClass().getClassLoader().getResource(YML_TEST_FILE);
if (url == null) {
throw new RuntimeException("File '" + YML_TEST_FILE + "' could not be loaded");
}
File file = new File(url.getFile());
messages = new Messages(file, "en");
}
@Test
public void shouldLoadMessages() {
// given
// when
String[] send = messages.send(MessageKey.CAPTCHA_WRONG_ERROR.getKey());
System.out.println(asList(send));
}
}

View File

@ -44,10 +44,14 @@ public class UtilsTest {
BukkitScheduler schedulerMock = mock(BukkitScheduler.class);
when(serverMock.getScheduler()).thenReturn(schedulerMock);
when(schedulerMock.runTaskAsynchronously(any(Plugin.class), any(Runnable.class)))
.thenReturn(mock(BukkitTask.class));
System.out.println("Initialized scheduler mock for server mock");
AuthMeMockUtil.insertMockWrapperInstance(Utils.class, "wrapper", (WrapperMock) wrapperMock);
System.out.println("Iniadfk");
permissionsManagerMock = mock(PermissionsManager.class);
when(authMeMock.getPermissionsManager()).thenReturn(permissionsManagerMock);