mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-30 23:15:50 +00:00
[AB-225] adding parameter handler for messages
reworking parameter handling in command received handler adding string parameter handler to explicitly parse strings
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
@@ -38,6 +40,12 @@ public class AChannelParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
@Mock
|
||||
private AChannel aChannel;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(AChannel.class));
|
||||
@@ -51,9 +59,9 @@ public class AChannelParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
@Test
|
||||
public void testProperChannelMention() {
|
||||
UnparsedCommandParameterPiece piece = getPiece();
|
||||
when(textChannelParameterHandler.handle(piece, iterators, TextChannel.class, message)).thenReturn(channel);
|
||||
when(textChannelParameterHandler.handle(piece, iterators, parameter, message, command)).thenReturn(channel);
|
||||
when(channelService.getFakeChannelFromTextChannel(channel)).thenReturn(aChannel);
|
||||
AChannel parsed = (AChannel) testUnit.handle(piece, iterators, TextChannel.class, message);
|
||||
AChannel parsed = (AChannel) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aChannel, parsed);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
@@ -27,6 +30,9 @@ public class AEmoteParameterHandlerImplImplTest extends AbstractParameterHandler
|
||||
@Mock
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@@ -39,6 +45,15 @@ public class AEmoteParameterHandlerImplImplTest extends AbstractParameterHandler
|
||||
@Mock
|
||||
private AEmote aEmote;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter2;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(AEmote.class));
|
||||
@@ -52,18 +67,20 @@ public class AEmoteParameterHandlerImplImplTest extends AbstractParameterHandler
|
||||
@Test
|
||||
public void testProperEmoteMention() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue(INPUT);
|
||||
when(emoteParameterHandler.handle(piece, iterators, Emote.class, message)).thenReturn(emote);
|
||||
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(emote);
|
||||
when(emoteService.getFakeEmoteFromEmote(emote)).thenReturn(aEmote);
|
||||
AEmote parsed = (AEmote) testUnit.handle(piece, iterators, AEmote.class, message);
|
||||
AEmote parsed = (AEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aEmote, parsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultEmoteHandling() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue(INPUT);
|
||||
when(emoteParameterHandler.handle(piece, iterators, Emote.class, message)).thenReturn(null);
|
||||
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(null);
|
||||
when(emoteService.getFakeEmote(INPUT)).thenReturn(aEmote);
|
||||
AEmote parsed = (AEmote) testUnit.handle(piece, iterators, AEmote.class, message);
|
||||
AEmote parsed = (AEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aEmote, parsed);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
@@ -27,6 +30,9 @@ public class ARoleParameterHandlerImplImplTest extends AbstractParameterHandlerT
|
||||
@Mock
|
||||
private RoleService roleService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@@ -39,6 +45,15 @@ public class ARoleParameterHandlerImplImplTest extends AbstractParameterHandlerT
|
||||
@Mock
|
||||
private ARole aRole;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter2;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(ARole.class));
|
||||
@@ -52,9 +67,10 @@ public class ARoleParameterHandlerImplImplTest extends AbstractParameterHandlerT
|
||||
@Test
|
||||
public void testProperRoleMention() {
|
||||
UnparsedCommandParameterPiece piece = getPiece();
|
||||
when(roleParameterHandler.handle(piece, iterators, Role.class, message)).thenReturn(role);
|
||||
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
|
||||
when(roleParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(role);
|
||||
when(roleService.getFakeRoleFromRole(role)).thenReturn(aRole);
|
||||
ARole parsed = (ARole) testUnit.handle(piece, iterators, AEmote.class, message);
|
||||
ARole parsed = (ARole) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aRole, parsed);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -13,6 +16,12 @@ public class BooleanParameterHandlerImplTest extends AbstractParameterHandlerTes
|
||||
@InjectMocks
|
||||
private BooleanParameterHandlerImpl testUnit;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Boolean.class));
|
||||
@@ -26,25 +35,25 @@ public class BooleanParameterHandlerImplTest extends AbstractParameterHandlerTes
|
||||
@Test
|
||||
public void testTrueParsing() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue("true");
|
||||
Assert.assertTrue((Boolean)testUnit.handle(piece, null, null, null));
|
||||
Assert.assertTrue((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyOtherText() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue("test");
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, null, null));
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullInput() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue(null);
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, null, null));
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue("");
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, null, null));
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -12,6 +15,12 @@ public class DoubleParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
@InjectMocks
|
||||
private DoubleParameterHandlerImpl testUnit;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Double.class));
|
||||
@@ -24,32 +33,32 @@ public class DoubleParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5D, testUnit.handle(getPieceWithValue("5"), null, null, null));
|
||||
Assert.assertEquals(5D, testUnit.handle(getPieceWithValue("5"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5D, testUnit.handle(getPieceWithValue("-5"), null, null, null));
|
||||
Assert.assertEquals(-5D, testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
|
||||
public void testDecimal() {
|
||||
Assert.assertEquals(3.14D, testUnit.handle(getPieceWithValue("3.14"), null, null, null));
|
||||
Assert.assertEquals(3.14D, testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, null, null);
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(getPieceWithValue(null), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(null), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.exception.DurationFormatException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -16,6 +19,12 @@ public class DurationParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
@InjectMocks
|
||||
private DurationParameterHandlerImpl testUnit;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Duration.class));
|
||||
@@ -28,23 +37,23 @@ public class DurationParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
|
||||
@Test
|
||||
public void testSimpleParsing() {
|
||||
Assert.assertEquals(Duration.ofMinutes(1), testUnit.handle(getPieceWithValue("1m"), null, null, null));
|
||||
Assert.assertEquals(Duration.ofMinutes(1), testUnit.handle(getPieceWithValue("1m"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoreComplicatedParsing() {
|
||||
Duration targetDuration = Duration.ofDays(4).plus(5, ChronoUnit.HOURS).plus(5, ChronoUnit.MINUTES);
|
||||
Assert.assertEquals(targetDuration, testUnit.handle(getPieceWithValue("5h5m4d"), null, null, null));
|
||||
Assert.assertEquals(targetDuration, testUnit.handle(getPieceWithValue("5h5m4d"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test(expected = DurationFormatException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(getPieceWithValue(null), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(null), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = DurationFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@@ -33,6 +35,12 @@ public class EmoteParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
private static final Long EMOTE_ID = 111111111111111111L;
|
||||
private static final String EMOTE_NAME = "test";
|
||||
|
||||
@@ -50,7 +58,7 @@ public class EmoteParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
public void testProperEmoteMention() {
|
||||
oneEmoteInIterator();
|
||||
String input = getEmoteMention();
|
||||
Emote parsed = (Emote) testUnit.handle(getPieceWithValue(input), iterators, Emote.class, null);
|
||||
Emote parsed = (Emote) testUnit.handle(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(parsed, emote);
|
||||
}
|
||||
|
||||
@@ -58,13 +66,13 @@ public class EmoteParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
public void testEmoteById() {
|
||||
setupMessage();
|
||||
String input = EMOTE_ID.toString();
|
||||
Emote parsed = (Emote) testUnit.handle(getPieceWithValue(input), null, Emote.class, message);
|
||||
Emote parsed = (Emote) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(parsed, emote);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidEmoteMention() {
|
||||
Assert.assertNull(testUnit.handle(getPieceWithValue("test"), null, Emote.class, null));
|
||||
Assert.assertNull(testUnit.handle(getPieceWithValue("test"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
private String getEmoteMention() {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
@@ -27,6 +30,9 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
@Mock
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@@ -39,6 +45,15 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
@Mock
|
||||
private AEmote aEmote;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter2;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(FullEmote.class));
|
||||
@@ -53,9 +68,10 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
public void testProperEmoteMention() {
|
||||
String input = "test";
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue(input);
|
||||
when(emoteParameterHandler.handle(piece, iterators, Emote.class, message)).thenReturn(emote);
|
||||
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(emote);
|
||||
when(emoteService.getFakeEmoteFromEmote(emote)).thenReturn(aEmote);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(piece, iterators, FullEmote.class, message);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aEmote, parsed.getFakeEmote());
|
||||
Assert.assertEquals(emote, parsed.getEmote());
|
||||
}
|
||||
@@ -65,9 +81,10 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
public void testDefaultEmoteHandling() {
|
||||
String input = "test";
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue(input);
|
||||
when(emoteParameterHandler.handle(piece, iterators, Emote.class, message)).thenReturn(null);
|
||||
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(null);
|
||||
when(emoteService.getFakeEmote(input)).thenReturn(aEmote);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(piece, iterators, AEmote.class, message);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertNull(parsed.getEmote());
|
||||
Assert.assertEquals(aEmote, parsed.getFakeEmote());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.models.FullRole;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
@@ -27,6 +30,9 @@ public class FullRoleParameterHandlerImplImplTest extends AbstractParameterHandl
|
||||
@Mock
|
||||
private RoleService roleService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@@ -39,6 +45,15 @@ public class FullRoleParameterHandlerImplImplTest extends AbstractParameterHandl
|
||||
@Mock
|
||||
private ARole aRole;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter2;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(FullRole.class));
|
||||
@@ -52,9 +67,10 @@ public class FullRoleParameterHandlerImplImplTest extends AbstractParameterHandl
|
||||
@Test
|
||||
public void testProperEmoteMention() {
|
||||
UnparsedCommandParameterPiece piece = getPiece();
|
||||
when(roleParameterHandler.handle(piece, iterators, Role.class, message)).thenReturn(role);
|
||||
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
|
||||
when(roleParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(role);
|
||||
when(roleService.getFakeRoleFromRole(role)).thenReturn(aRole);
|
||||
FullRole parsed = (FullRole) testUnit.handle(piece, iterators, FullRole.class, message);
|
||||
FullRole parsed = (FullRole) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aRole, parsed.getRole());
|
||||
Assert.assertEquals(role, parsed.getServerRole());
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -12,6 +15,12 @@ public class IntegerParameterHandlerImplTest extends AbstractParameterHandlerTes
|
||||
@InjectMocks
|
||||
private IntegerParameterHandlerImpl testUnit;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Integer.class));
|
||||
@@ -24,33 +33,33 @@ public class IntegerParameterHandlerImplTest extends AbstractParameterHandlerTes
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5, testUnit.handle(getPieceWithValue("5"), null, null, null));
|
||||
Assert.assertEquals(5, testUnit.handle(getPieceWithValue("5"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5, testUnit.handle(getPieceWithValue("-5"), null, null, null));
|
||||
Assert.assertEquals(-5, testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testDecimal() {
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, null, null);
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, null, null);
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(getPieceWithValue(null), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(null), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -12,6 +15,12 @@ public class LongParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
@InjectMocks
|
||||
private LongParameterHandlerImpl testUnit;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Long.class));
|
||||
@@ -24,32 +33,32 @@ public class LongParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5L, testUnit.handle(getPieceWithValue("5"), null, null, null));
|
||||
Assert.assertEquals(5L, testUnit.handle(getPieceWithValue("5"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5L, testUnit.handle(getPieceWithValue("-5"), null, null, null));
|
||||
Assert.assertEquals(-5L, testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testDecimal() {
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, null, null);
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, null, null);
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(getPieceWithValue(null), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(null), null, parameter, null, command);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, null, null);
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
@@ -38,6 +40,12 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
private static final Long USER_ID = 111111111111111111L;
|
||||
|
||||
@Test
|
||||
@@ -55,7 +63,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
public void testProperMemberMention() {
|
||||
oneMemberInIterator();
|
||||
String input = getUserMention();
|
||||
CompletableFuture<Member> parsed = (CompletableFuture) testUnit.handleAsync(getPieceWithValue(input), iterators, Member.class, null);
|
||||
CompletableFuture<Member> parsed = (CompletableFuture) testUnit.handleAsync(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(member, parsed.join());
|
||||
}
|
||||
|
||||
@@ -64,7 +72,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
public void testMemberById() {
|
||||
setupMessage();
|
||||
String input = USER_ID.toString();
|
||||
CompletableFuture<Member> parsed = (CompletableFuture) testUnit.handleAsync(getPieceWithValue(input), null, Member.class, message);
|
||||
CompletableFuture<Member> parsed = (CompletableFuture) testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(member, parsed.join());
|
||||
}
|
||||
|
||||
@@ -73,7 +81,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMembersByName(input, true)).thenReturn(new ArrayList<>());
|
||||
testUnit.handleAsync(getPieceWithValue(input), null, Member.class, message);
|
||||
testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@@ -82,7 +90,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
Member secondMember = Mockito.mock(Member.class);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMembersByName(input, true)).thenReturn(Arrays.asList(member, secondMember));
|
||||
testUnit.handleAsync(getPieceWithValue(input), null, Member.class, message);
|
||||
testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,7 +98,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMembersByName(input, true)).thenReturn(Arrays.asList(member));
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, Member.class, message);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Member returnedMember = (Member) future.join();
|
||||
Assert.assertFalse(future.isCompletedExceptionally());
|
||||
Assert.assertEquals(member, returnedMember);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@@ -36,6 +38,12 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
private static final Long ROLE_ID = 111111111111111111L;
|
||||
|
||||
@Test
|
||||
@@ -52,7 +60,7 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
public void testProperRoleMention() {
|
||||
oneRoleIterator();
|
||||
String input = getRoleMention();
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), iterators, Role.class, null);
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(role, parsed);
|
||||
}
|
||||
|
||||
@@ -60,7 +68,7 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
public void testRoleById() {
|
||||
setupMessage();
|
||||
String input = ROLE_ID.toString();
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), null, Role.class, message);
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(role, parsed);
|
||||
}
|
||||
|
||||
@@ -69,7 +77,7 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getRolesByName(input, true)).thenReturn(new ArrayList<>());
|
||||
testUnit.handle(getPieceWithValue(input), null, Role.class, message);
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@@ -78,7 +86,7 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
Role secondRole = Mockito.mock(Role.class);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getRolesByName(input, true)).thenReturn(Arrays.asList(role, secondRole));
|
||||
testUnit.handle(getPieceWithValue(input), null, Role.class, message);
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +94,7 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getRolesByName(input, true)).thenReturn(Arrays.asList(role));
|
||||
Role returnedRole = (Role) testUnit.handle(getPieceWithValue(input), null, Role.class, message);
|
||||
Role returnedRole = (Role) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(role, returnedRole);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@@ -36,6 +38,12 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
@Mock
|
||||
private Parameter parameter;
|
||||
|
||||
@Mock
|
||||
private Command command;
|
||||
|
||||
private static final Long CHANNEL_ID = 111111111111111111L;
|
||||
|
||||
@Test
|
||||
@@ -52,7 +60,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
public void testProperChannelMention() {
|
||||
oneChannelInIterator();
|
||||
String input = getChannelMention();
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(getPieceWithValue(input), iterators, TextChannel.class, null);
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(channel, parsed);
|
||||
}
|
||||
|
||||
@@ -60,7 +68,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
public void testChannelMentionById() {
|
||||
setupMessage();
|
||||
String input = CHANNEL_ID.toString();
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(getPieceWithValue(input), null, TextChannel.class, message);
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(channel, parsed);
|
||||
}
|
||||
|
||||
@@ -69,7 +77,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getTextChannelsByName(input, true)).thenReturn(new ArrayList<>());
|
||||
testUnit.handle(getPieceWithValue(input), null, TextChannel.class, message);
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@@ -78,7 +86,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
TextChannel secondChannel = Mockito.mock(TextChannel.class);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getTextChannelsByName(input, true)).thenReturn(Arrays.asList(channel, secondChannel));
|
||||
testUnit.handle(getPieceWithValue(input), null, TextChannel.class, message);
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +94,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getTextChannelsByName(input, true)).thenReturn(Arrays.asList(channel));
|
||||
TextChannel returnedChannel = (TextChannel) testUnit.handle(getPieceWithValue(input), null, TextChannel.class, message);
|
||||
TextChannel returnedChannel = (TextChannel) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(channel, returnedChannel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user