mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-07 01:30:49 +00:00
[AB-54] adding various command parameter handlers
removing old parameter length validation
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
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 static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AChannelParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private AChannelParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private TextChannelParameterHandler textChannelParameterHandler;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private TextChannel channel;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private AChannel aChannel;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(AChannel.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperChannelMention() {
|
||||
String input = "test";
|
||||
when(textChannelParameterHandler.handle(input, iterators, TextChannel.class, message)).thenReturn(channel);
|
||||
when(channelService.getFakeChannelFromTextChannel(channel)).thenReturn(aChannel);
|
||||
AChannel parsed = (AChannel) testUnit.handle(input, iterators, TextChannel.class, message);
|
||||
Assert.assertEquals(aChannel, parsed);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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 static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AEmoteParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private AEmoteParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private EmoteParameterHandler emoteParameterHandler;
|
||||
|
||||
@Mock
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Emote emote;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private AEmote aEmote;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(AEmote.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperEmoteMention() {
|
||||
String input = "test";
|
||||
when(emoteParameterHandler.handle(input, iterators, Emote.class, message)).thenReturn(emote);
|
||||
when(emoteService.getFakeEmoteFromEmote(emote)).thenReturn(aEmote);
|
||||
AEmote parsed = (AEmote) testUnit.handle(input, iterators, AEmote.class, message);
|
||||
Assert.assertEquals(aEmote, parsed);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
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 static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ARoleParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private ARoleParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private RoleParameterHandler roleParameterHandler;
|
||||
|
||||
@Mock
|
||||
private RoleService roleService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Role role;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private ARole aRole;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(ARole.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperRoleMention() {
|
||||
String input = "test";
|
||||
when(roleParameterHandler.handle(input, iterators, Role.class, message)).thenReturn(role);
|
||||
when(roleService.getFakeRoleFromRole(role)).thenReturn(aRole);
|
||||
ARole parsed = (ARole) testUnit.handle(input, iterators, AEmote.class, message);
|
||||
Assert.assertEquals(aRole, parsed);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BooleanParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private BooleanParameterHandler testUnit;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueParsing() {
|
||||
Assert.assertTrue((Boolean)testUnit.handle("true", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyOtherText() {
|
||||
Assert.assertFalse((Boolean)testUnit.handle("test", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullInput() {
|
||||
Assert.assertFalse((Boolean)testUnit.handle(null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
Assert.assertFalse((Boolean)testUnit.handle("", null, null, null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DoubleParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private DoubleParameterHandler testUnit;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Double.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5D, testUnit.handle("5", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5D, testUnit.handle("-5", null, null, null));
|
||||
}
|
||||
|
||||
|
||||
public void testDecimal() {
|
||||
Assert.assertEquals(3.14D, testUnit.handle("3.14", null, null, null));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle("someText", null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle("", null, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
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.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DurationParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private DurationParameterHandler testUnit;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Duration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleParsing() {
|
||||
Assert.assertEquals(Duration.ofMinutes(1), testUnit.handle("1m", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoreComplicatedParsing() {
|
||||
Duration targetDuration = Duration.ofDays(4).plus(5, ChronoUnit.HOURS).plus(5, ChronoUnit.MINUTES);
|
||||
Assert.assertEquals(targetDuration, testUnit.handle("5m5h4d", null, null, null));
|
||||
}
|
||||
|
||||
@Test(expected = DurationFormatException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = DurationFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle("", null, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EmoteParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private EmoteParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Emote emote;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
private static final Long EMOTE_ID = 111111111111111111L;
|
||||
private static final String EMOTE_NAME = "test";
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Emote.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperEmoteMention() {
|
||||
oneEmoteInIterator();
|
||||
String input = getEmoteMention();
|
||||
Emote parsed = (Emote) testUnit.handle(input, iterators, Emote.class, null);
|
||||
Assert.assertEquals(parsed, emote);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmoteById() {
|
||||
setupMessage();
|
||||
String input = EMOTE_ID.toString();
|
||||
Emote parsed = (Emote) testUnit.handle(input, null, Emote.class, message);
|
||||
Assert.assertEquals(parsed, emote);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testInvalidEmoteMention() {
|
||||
String input = "test";
|
||||
testUnit.handle(input, null, Emote.class, null);
|
||||
}
|
||||
|
||||
private String getEmoteMention() {
|
||||
return String.format("<:%s:%d>", EMOTE_NAME, EMOTE_ID);
|
||||
}
|
||||
|
||||
private void oneEmoteInIterator() {
|
||||
List<Emote> emotes = Arrays.asList(emote);
|
||||
when(iterators.getEmoteIterator()).thenReturn(emotes.iterator());
|
||||
}
|
||||
|
||||
private void setupMessage() {
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(emote);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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 static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class FullEmoteParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private FullEmoteParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private EmoteParameterHandler emoteParameterHandler;
|
||||
|
||||
@Mock
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Emote emote;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private AEmote aEmote;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(FullEmote.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperEmoteMention() {
|
||||
String input = "test";
|
||||
when(emoteParameterHandler.handle(input, iterators, Emote.class, message)).thenReturn(emote);
|
||||
when(emoteService.getFakeEmoteFromEmote(emote)).thenReturn(aEmote);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(input, iterators, FullEmote.class, message);
|
||||
Assert.assertEquals(aEmote, parsed.getFakeEmote());
|
||||
Assert.assertEquals(emote, parsed.getEmote());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullRole;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
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 static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class FullRoleParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private FullRoleParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private RoleParameterHandler roleParameterHandler;
|
||||
|
||||
@Mock
|
||||
private RoleService roleService;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Role role;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private ARole aRole;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(FullRole.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperEmoteMention() {
|
||||
String input = "test";
|
||||
when(roleParameterHandler.handle(input, iterators, Role.class, message)).thenReturn(role);
|
||||
when(roleService.getFakeRoleFromRole(role)).thenReturn(aRole);
|
||||
FullRole parsed = (FullRole) testUnit.handle(input, iterators, FullRole.class, message);
|
||||
Assert.assertEquals(aRole, parsed.getRole());
|
||||
Assert.assertEquals(role, parsed.getServerRole());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class IntegerParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private IntegerParameterHandler testUnit;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5, testUnit.handle("5", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5, testUnit.handle("-5", null, null, null));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testDecimal() {
|
||||
testUnit.handle("3.14", null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle("someText", null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle("", null, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LongParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private LongParameterHandler testUnit;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Long.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5L, testUnit.handle("5", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5L, testUnit.handle("-5", null, null, null));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testDecimal() {
|
||||
testUnit.handle("3.14", null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle("someText", null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testNullInput() {
|
||||
testUnit.handle(null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle("", null, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
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.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MemberParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private MemberParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Member member;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
private static final Long USER_ID = 111111111111111111L;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Member.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperMemberMention() {
|
||||
oneMemberInIterator();
|
||||
String input = getUserMention();
|
||||
Member parsed = (Member) testUnit.handle(input, iterators, Member.class, null);
|
||||
Assert.assertEquals(parsed, member);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemberById() {
|
||||
setupMessage();
|
||||
String input = USER_ID.toString();
|
||||
Member parsed = (Member) testUnit.handle(input, null, Member.class, message);
|
||||
Assert.assertEquals(parsed, member);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testInvalidMemberMention() {
|
||||
String input = "test";
|
||||
testUnit.handle(input, null, Member.class, null);
|
||||
}
|
||||
|
||||
private String getUserMention() {
|
||||
return String.format("<@%d>", USER_ID);
|
||||
}
|
||||
|
||||
private void oneMemberInIterator() {
|
||||
List<Member> members = Arrays.asList(member);
|
||||
when(iterators.getMemberIterator()).thenReturn(members.iterator());
|
||||
}
|
||||
|
||||
private void setupMessage() {
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMemberById(USER_ID)).thenReturn(member);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
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.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RoleParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private RoleParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private Role role;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
private static final Long ROLE_ID = 111111111111111111L;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(Role.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperRoleMention() {
|
||||
oneRoleIterator();
|
||||
String input = getRoleMention();
|
||||
Role parsed = (Role) testUnit.handle(input, iterators, Role.class, null);
|
||||
Assert.assertEquals(parsed, role);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoleById() {
|
||||
setupMessage();
|
||||
String input = ROLE_ID.toString();
|
||||
Role parsed = (Role) testUnit.handle(input, null, Role.class, message);
|
||||
Assert.assertEquals(parsed, role);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testInvalidRoleMention() {
|
||||
String input = "test";
|
||||
testUnit.handle(input, null, Role.class, null);
|
||||
}
|
||||
|
||||
private String getRoleMention() {
|
||||
return String.format("<@&%d>", ROLE_ID);
|
||||
}
|
||||
|
||||
private void oneRoleIterator() {
|
||||
List<Role> members = Arrays.asList(role);
|
||||
when(iterators.getRoleIterator()).thenReturn(members.iterator());
|
||||
}
|
||||
|
||||
private void setupMessage() {
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getRoleById(ROLE_ID)).thenReturn(role);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
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.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TextChannelParameterHandlerTest {
|
||||
|
||||
@InjectMocks
|
||||
private TextChannelParameterHandler testUnit;
|
||||
|
||||
@Mock
|
||||
private CommandParameterIterators iterators;
|
||||
|
||||
@Mock
|
||||
private TextChannel channel;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
private static final Long CHANNEL_ID = 111111111111111111L;
|
||||
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
Assert.assertTrue(testUnit.handles(TextChannel.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperChannelMention() {
|
||||
oneChannelInIterator();
|
||||
String input = getChannelMention();
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(input, iterators, TextChannel.class, null);
|
||||
Assert.assertEquals(parsed, channel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelMentionById() {
|
||||
setupMessage();
|
||||
String input = CHANNEL_ID.toString();
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(input, null, TextChannel.class, message);
|
||||
Assert.assertEquals(parsed, channel);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void testInvalidChannelMention() {
|
||||
String input = "test";
|
||||
testUnit.handle(input, null, TextChannel.class, null);
|
||||
}
|
||||
|
||||
private String getChannelMention() {
|
||||
return String.format("<#%d>", CHANNEL_ID);
|
||||
}
|
||||
|
||||
private void oneChannelInIterator() {
|
||||
List<TextChannel> channels = Arrays.asList(channel);
|
||||
when(iterators.getChannelIterator()).thenReturn(channels.iterator());
|
||||
}
|
||||
|
||||
private void setupMessage() {
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getTextChannelById(CHANNEL_ID)).thenReturn(channel);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user