Create delayed injection test runner

- Test runner supporting new "DelayedInjection" annotation: such fields are only initialized with instantiation right before the first time they're used in tests, allowing to set up mock behavior beforehand
This commit is contained in:
ljacqu
2016-06-18 13:19:07 +02:00
parent cd1acfde1b
commit a1c62e7c04
13 changed files with 296 additions and 126 deletions
@@ -1,5 +1,7 @@
package fr.xephi.authme.command;
import fr.xephi.authme.DelayedInject;
import fr.xephi.authme.DelayedInjectionRunner;
import fr.xephi.authme.command.TestCommandsUtil.TestLoginCommand;
import fr.xephi.authme.command.TestCommandsUtil.TestRegisterCommand;
import fr.xephi.authme.command.TestCommandsUtil.TestUnregisterCommand;
@@ -10,6 +12,8 @@ import org.bukkit.command.CommandSender;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import java.util.List;
import java.util.Set;
@@ -32,12 +36,20 @@ import static org.mockito.Mockito.mock;
/**
* Test for {@link CommandMapper}.
*/
@RunWith(DelayedInjectionRunner.class)
public class CommandMapperTest {
private static Set<CommandDescription> commands;
@DelayedInject
private CommandMapper mapper;
@Mock
private PermissionsManager permissionsManager;
@Mock
private CommandInitializer commandInitializer;
@BeforeClass
public static void setUpCommandHandler() {
commands = TestCommandsUtil.generateCommands();
@@ -45,10 +57,7 @@ public class CommandMapperTest {
@Before
public void setUpMocks() {
permissionsManager = mock(PermissionsManager.class);
CommandInitializer initializer = mock(CommandInitializer.class);
given(initializer.getCommands()).willReturn(commands);
mapper = new CommandMapper(initializer, permissionsManager);
given(commandInitializer.getCommands()).willReturn(commands);
}
// -----------