Create Wrapper for instances / revise MockUtils

- Add test resources folder
- Create basic test for Messages (todo: add concrete tests)
- Create WrapperMock
- Change UtilsTest (todo: make it work)
This commit is contained in:
ljacqu
2015-11-23 23:25:03 +01:00
parent 8719cce334
commit 6422f90114
11 changed files with 261 additions and 51 deletions
@@ -2,6 +2,7 @@ package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.AuthMeMockUtil;
import fr.xephi.authme.WrapperMock;
import fr.xephi.authme.permission.PermissionsManager;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@@ -9,6 +10,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.lang.reflect.Field;
@@ -23,26 +25,32 @@ import static org.mockito.Mockito.when;
/**
* Test for the {@link Utils} class.
*/
@Ignore
// TODO ljacqu 20151123: Fix test setup
public class UtilsTest {
private AuthMe authMeMock;
private PermissionsManager permissionsManagerMock;
private Wrapper wrapperMock;
@Before
public void setUpMocks() {
AuthMeMockUtil.mockAuthMeInstance();
authMeMock = AuthMe.getInstance();
authMeMock = AuthMeMockUtil.mockAuthMeInstance();
permissionsManagerMock = mock(PermissionsManager.class);
when(authMeMock.getPermissionsManager()).thenReturn(permissionsManagerMock);
Server serverMock = mock(Server.class);
when(authMeMock.getGameServer()).thenReturn(serverMock);
// We need to create the Wrapper mock before injecting it into Utils because it runs a lot of code in
// a static block which needs the proper mocks to be set up.
wrapperMock = new WrapperMock(authMeMock);
Server serverMock = wrapperMock.getServer();
BukkitScheduler schedulerMock = mock(BukkitScheduler.class);
when(serverMock.getScheduler()).thenReturn(schedulerMock);
when(schedulerMock.runTaskAsynchronously(any(Plugin.class), any(Runnable.class)))
.thenReturn(mock(BukkitTask.class));
.thenReturn(mock(BukkitTask.class));
AuthMeMockUtil.insertMockWrapperInstance(Utils.class, "wrapper", (WrapperMock) wrapperMock);
permissionsManagerMock = mock(PermissionsManager.class);
when(authMeMock.getPermissionsManager()).thenReturn(permissionsManagerMock);
}
// TODO ljacques 20151122: The tests for Utils.forceGM somehow can't be set up with the mocks correctly