mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 09:10:01 +01:00
Fix generics in ConverterCommandTest
This commit is contained in:
parent
4df4e823ec
commit
6857bd929e
@ -4,8 +4,6 @@ import ch.jalu.injector.Injector;
|
|||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.converter.Converter;
|
import fr.xephi.authme.converter.Converter;
|
||||||
import fr.xephi.authme.converter.RakamakConverter;
|
|
||||||
import fr.xephi.authme.converter.vAuthConverter;
|
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.util.BukkitService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
@ -92,9 +90,7 @@ public class ConverterCommandTest {
|
|||||||
// given
|
// given
|
||||||
String converterName = "rakamak";
|
String converterName = "rakamak";
|
||||||
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||||
// Keep concrete class reference in mock: if this class is ever removed, we need to use another converterName
|
Converter converter = createMockReturnedByInjector(converterClass);
|
||||||
Converter converter = mock(RakamakConverter.class);
|
|
||||||
given(injector.newInstance(converterClass)).willReturn(converter);
|
|
||||||
CommandSender sender = mock(CommandSender.class);
|
CommandSender sender = mock(CommandSender.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -113,9 +109,8 @@ public class ConverterCommandTest {
|
|||||||
// given
|
// given
|
||||||
String converterName = "vauth";
|
String converterName = "vauth";
|
||||||
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||||
Converter converter = mock(vAuthConverter.class);
|
Converter converter = createMockReturnedByInjector(converterClass);
|
||||||
doThrow(IllegalStateException.class).when(converter).execute(any(CommandSender.class));
|
doThrow(IllegalStateException.class).when(converter).execute(any(CommandSender.class));
|
||||||
given(injector.newInstance(converterClass)).willReturn(converter);
|
|
||||||
CommandSender sender = mock(CommandSender.class);
|
CommandSender sender = mock(CommandSender.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -130,4 +125,10 @@ public class ConverterCommandTest {
|
|||||||
verify(commandService).send(sender, MessageKey.ERROR);
|
verify(commandService).send(sender, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends Converter> T createMockReturnedByInjector(Class<T> clazz) {
|
||||||
|
T converter = mock(clazz);
|
||||||
|
given(injector.newInstance(clazz)).willReturn(converter);
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user