mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-02 16:05:00 +00:00
[AB-xxx] adding unit test for server controller
refactoring parameter parsing tests to use assertj
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package dev.sheldan.abstracto.core.api;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.GuildNotFoundException;
|
||||
import dev.sheldan.abstracto.core.models.api.GuildDisplay;
|
||||
import dev.sheldan.abstracto.core.service.GuildService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
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.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ServerControllerTest {
|
||||
@InjectMocks
|
||||
private ServerController unitToTest;
|
||||
|
||||
@Mock
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Mock
|
||||
private GuildService guildService;
|
||||
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
private static final Long GUILD_ID = 1L;
|
||||
|
||||
@Test
|
||||
public void testExecuteRequest() {
|
||||
when(guildService.getGuildById(GUILD_ID)).thenReturn(guild);
|
||||
String guildIdString = String.valueOf(GUILD_ID);
|
||||
when(guild.getId()).thenReturn(guildIdString);
|
||||
GuildDisplay response = unitToTest.getLeaderboard(GUILD_ID);
|
||||
assertThat(response.getId()).isEqualTo(guildIdString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteServerNotFound() {
|
||||
when(serverManagementService.loadServer(GUILD_ID)).thenThrow(new GuildNotFoundException(GUILD_ID));
|
||||
assertThatThrownBy(() -> unitToTest.getLeaderboard(GUILD_ID))
|
||||
.isInstanceOf(GuildNotFoundException.class)
|
||||
.hasMessageContaining("Guild not found");
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ 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.channel.concrete.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.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -53,12 +53,12 @@ public class AChannelParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(AChannel.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(AChannel.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +67,7 @@ public class AChannelParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
when(textChannelParameterHandler.handle(piece, iterators, parameter, message, command)).thenReturn(channel);
|
||||
when(channelService.getFakeChannelFromTextChannel(channel)).thenReturn(aChannel);
|
||||
AChannel parsed = (AChannel) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aChannel, parsed);
|
||||
assertThat(parsed).isEqualTo(aChannel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||
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.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -61,12 +61,12 @@ public class AEmoteParameterHandlerImplImplTest extends AbstractParameterHandler
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(AEmote.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(AEmote.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +76,7 @@ public class AEmoteParameterHandlerImplImplTest extends AbstractParameterHandler
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(emote);
|
||||
when(emoteService.getFakeEmoteFromEmote(emote)).thenReturn(aEmote);
|
||||
AEmote parsed = (AEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aEmote, parsed);
|
||||
assertThat(parsed).isEqualTo(aEmote);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +86,7 @@ public class AEmoteParameterHandlerImplImplTest extends AbstractParameterHandler
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(null);
|
||||
when(emoteService.getFakeEmote(INPUT)).thenReturn(aEmote);
|
||||
AEmote parsed = (AEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aEmote, parsed);
|
||||
assertThat(parsed).isEqualTo(aEmote);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ 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.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -60,12 +60,12 @@ public class ARoleParameterHandlerImplImplTest extends AbstractParameterHandlerT
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(ARole.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(ARole.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +75,7 @@ public class ARoleParameterHandlerImplImplTest extends AbstractParameterHandlerT
|
||||
when(roleParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(role);
|
||||
when(roleService.getFakeRoleFromRole(role)).thenReturn(aRole);
|
||||
ARole parsed = (ARole) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aRole, parsed);
|
||||
assertThat(parsed).isEqualTo(aRole);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.ParameterPieceType;
|
||||
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;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -31,30 +31,30 @@ public class BooleanParameterHandlerImplTest extends AbstractParameterHandlerTes
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Boolean.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Boolean.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueParsing() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue("true");
|
||||
Assert.assertTrue((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
assertThat((Boolean)testUnit.handle(piece, null, parameter, null, command)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyOtherText() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue("test");
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
assertThat((Boolean)testUnit.handle(piece, null, parameter, null, command)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
UnparsedCommandParameterPiece piece = getPieceWithValue("");
|
||||
Assert.assertFalse((Boolean)testUnit.handle(piece, null, parameter, null, command));
|
||||
assertThat((Boolean)testUnit.handle(piece, null, parameter, null, command)).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.ParameterPieceType;
|
||||
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;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -31,42 +31,49 @@ public class DoubleParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Double.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Double.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5D, testUnit.handle(getPieceWithValue("5"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("5"), null, parameter, null, command)).isEqualTo(5D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5D, testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("-50"), null, parameter, null, command)).isEqualTo(-50D);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecimal() {
|
||||
Assert.assertEquals(3.14D, testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command)).isEqualTo(3.14D);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testNullInput() {
|
||||
testUnit.handle(getPieceWithValue(null), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(null), null, parameter, null, command);
|
||||
}).isInstanceOf(NullPointerException.class);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.ParameterPieceType;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.exception.DurationFormatException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -15,6 +14,8 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -35,28 +36,30 @@ public class DurationParameterHandlerImplTest extends AbstractParameterHandlerTe
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Duration.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Duration.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleParsing() {
|
||||
Assert.assertEquals(Duration.ofMinutes(1), testUnit.handle(getPieceWithValue("1m"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("1m"), null, parameter, null, command)).isEqualTo(Duration.ofMinutes(1));
|
||||
}
|
||||
|
||||
@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, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("5h5m4d"), null, parameter, null, command)).isEqualTo(targetDuration);
|
||||
}
|
||||
|
||||
@Test(expected = DurationFormatException.class)
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}).isInstanceOf(DurationFormatException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -18,6 +17,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -53,12 +53,12 @@ public class EmoteParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(CustomEmoji.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(CustomEmoji.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +66,7 @@ public class EmoteParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
oneEmoteInIterator();
|
||||
String input = getEmoteMention();
|
||||
CustomEmoji parsed = (CustomEmoji) testUnit.handle(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(parsed, emote);
|
||||
assertThat(parsed).isEqualTo(emote);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,12 +74,12 @@ public class EmoteParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
setupMessage();
|
||||
String input = EMOTE_ID.toString();
|
||||
CustomEmoji parsed = (CustomEmoji) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(parsed, emote);
|
||||
assertThat(parsed).isEqualTo(emote);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidEmoteMention() {
|
||||
Assert.assertNull(testUnit.handle(getPieceWithValue("test"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("test"), null, parameter, null, command)).isNull();
|
||||
}
|
||||
|
||||
private String getEmoteMention() {
|
||||
|
||||
@@ -10,13 +10,13 @@ import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||
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.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -61,12 +61,12 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(FullEmote.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(FullEmote.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,8 +77,8 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(emote);
|
||||
when(emoteService.getFakeEmoteFromEmote(emote)).thenReturn(aEmote);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aEmote, parsed.getFakeEmote());
|
||||
Assert.assertEquals(emote, parsed.getEmote());
|
||||
assertThat(parsed.getFakeEmote()).isEqualTo(aEmote);
|
||||
assertThat(parsed.getEmote()).isEqualTo(emote);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,8 +90,8 @@ public class FullEmoteParameterHandlerImplImplTest extends AbstractParameterHand
|
||||
when(emoteParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(null);
|
||||
when(emoteService.getFakeEmote(input)).thenReturn(aEmote);
|
||||
FullEmote parsed = (FullEmote) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertNull(parsed.getEmote());
|
||||
Assert.assertEquals(aEmote, parsed.getFakeEmote());
|
||||
assertThat(parsed.getEmote()).isNull();
|
||||
assertThat(parsed.getFakeEmote()).isEqualTo(aEmote);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ 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.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -61,12 +61,12 @@ public class FullRoleParameterHandlerImplImplTest extends AbstractParameterHandl
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(FullRole.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(FullRole.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,8 +76,8 @@ public class FullRoleParameterHandlerImplImplTest extends AbstractParameterHandl
|
||||
when(roleParameterHandler.handle(piece, iterators, parameter2, message, command)).thenReturn(role);
|
||||
when(roleService.getFakeRoleFromRole(role)).thenReturn(aRole);
|
||||
FullRole parsed = (FullRole) testUnit.handle(piece, iterators, parameter, message, command);
|
||||
Assert.assertEquals(aRole, parsed.getRole());
|
||||
Assert.assertEquals(role, parsed.getServerRole());
|
||||
assertThat(parsed.getRole()).isEqualTo(aRole);
|
||||
assertThat(parsed.getServerRole()).isEqualTo(role);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@ import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.ParameterPieceType;
|
||||
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;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -31,38 +32,44 @@ public class IntegerParameterHandlerImplTest extends AbstractParameterHandlerTes
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Integer.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Integer.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5, testUnit.handle(getPieceWithValue("5"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("5"), null, parameter, null, command)).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5, testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command)).isEqualTo(-5);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testDecimal() {
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.ParameterPieceType;
|
||||
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;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -31,37 +32,43 @@ public class LongParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Long.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Long.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulParse() {
|
||||
Assert.assertEquals(5L, testUnit.handle(getPieceWithValue("5"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("5"), null, parameter, null, command)).isEqualTo(5L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNumber() {
|
||||
Assert.assertEquals(-5L, testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command));
|
||||
assertThat(testUnit.handle(getPieceWithValue("-5"), null, parameter, null, command)).isEqualTo(-5L);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testDecimal() {
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue("3.14"), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testTextAsInput() {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue("someText"), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testEmptyStringAsInput() {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(""), null, parameter, null, command);
|
||||
}).isInstanceOf(NumberFormatException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.requests.restaction.CacheRestAction;
|
||||
import net.dv8tion.jda.internal.utils.concurrent.task.GatewayTask;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -22,6 +21,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -56,12 +56,12 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Member.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Member.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,7 +70,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
oneMemberInIterator();
|
||||
String input = getUserMention();
|
||||
CompletableFuture<Member> parsed = (CompletableFuture) testUnit.handleAsync(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(member, parsed.join());
|
||||
assertThat(parsed.join()).isEqualTo(member);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +79,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
setupMessage();
|
||||
String input = USER_ID.toString();
|
||||
CompletableFuture<Member> parsed = (CompletableFuture) testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(member, parsed.join());
|
||||
assertThat(parsed.join()).isEqualTo(member);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +89,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
GatewayTask task = new GatewayTask(CompletableFuture.completedFuture(new ArrayList()), () -> {});
|
||||
when(guild.retrieveMembersByPrefix(input, 1)).thenReturn(task);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertTrue(future.isCompletedExceptionally());
|
||||
assertThat(future.isCompletedExceptionally()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,7 +100,7 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
GatewayTask task = new GatewayTask(CompletableFuture.completedFuture(Arrays.asList(member, secondMember)), () -> {});
|
||||
when(guild.retrieveMembersByPrefix(input, 1)).thenReturn(task);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertTrue(future.isCompletedExceptionally());
|
||||
assertThat(future.isCompletedExceptionally()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,8 +111,8 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
when(guild.retrieveMembersByPrefix(input, 1)).thenReturn(task);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Member returnedMember = (Member) future.join();
|
||||
Assert.assertFalse(future.isCompletedExceptionally());
|
||||
Assert.assertEquals(member, returnedMember);
|
||||
assertThat(future.isCompletedExceptionally()).isFalse();
|
||||
assertThat(returnedMember).isEqualTo(member);
|
||||
}
|
||||
|
||||
private String getUserMention() {
|
||||
|
||||
@@ -8,7 +8,6 @@ import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiec
|
||||
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;
|
||||
@@ -18,8 +17,9 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -54,20 +54,20 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(Role.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(Role.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperRoleMention() {
|
||||
oneRoleIterator();
|
||||
setupMessage();
|
||||
String input = getRoleMention();
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(role, parsed);
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), iterators, parameter, message, command);
|
||||
assertThat(parsed).isEqualTo(role);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,24 +75,29 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
setupMessage();
|
||||
String input = ROLE_ID.toString();
|
||||
Role parsed = (Role) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(role, parsed);
|
||||
assertThat(parsed).isEqualTo(role);
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@Test
|
||||
public void testInvalidRoleMention() {
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getRolesByName(input, true)).thenReturn(new ArrayList<>());
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}).isInstanceOf(AbstractoTemplatedException.class);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@Test
|
||||
public void testMultipleRolesFoundByName() {
|
||||
String input = "test";
|
||||
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, parameter, message, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}).isInstanceOf(AbstractoTemplatedException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,21 +106,16 @@ public class RoleParameterHandlerImplTest extends AbstractParameterHandlerTest {
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getRolesByName(input, true)).thenReturn(Arrays.asList(role));
|
||||
Role returnedRole = (Role) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(role, returnedRole);
|
||||
assertThat(returnedRole).isEqualTo(role);
|
||||
}
|
||||
|
||||
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);
|
||||
when(guild.getRoleById(String.valueOf(ROLE_ID))).thenReturn(role);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiec
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -20,6 +19,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -54,12 +55,12 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
@Test
|
||||
public void testSuccessfulCondition() {
|
||||
when(unparsedCommandParameterPiece.getType()).thenReturn(ParameterPieceType.STRING);
|
||||
Assert.assertTrue(testUnit.handles(TextChannel.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(TextChannel.class, unparsedCommandParameterPiece)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCondition() {
|
||||
Assert.assertFalse(testUnit.handles(String.class, unparsedCommandParameterPiece));
|
||||
assertThat(testUnit.handles(String.class, unparsedCommandParameterPiece)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +68,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
oneChannelInIterator();
|
||||
String input = getChannelMention();
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(getPieceWithValue(input), iterators, parameter, null, command);
|
||||
Assert.assertEquals(channel, parsed);
|
||||
assertThat(parsed).isEqualTo(channel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,24 +76,28 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
setupMessage();
|
||||
String input = CHANNEL_ID.toString();
|
||||
TextChannel parsed = (TextChannel) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(channel, parsed);
|
||||
assertThat(parsed).isEqualTo(channel);
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@Test
|
||||
public void testInvalidChannelName() {
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getTextChannelsByName(input, true)).thenReturn(new ArrayList<>());
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}).isInstanceOf(AbstractoTemplatedException.class);
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@Test
|
||||
public void testFoundMultipleChannelsByName() {
|
||||
String input = "test";
|
||||
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, parameter, message, command);
|
||||
assertThatThrownBy(() -> {
|
||||
testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
}).isInstanceOf(AbstractoTemplatedException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +106,7 @@ public class TextChannelParameterHandlerImplTest extends AbstractParameterHandle
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getTextChannelsByName(input, true)).thenReturn(Arrays.asList(channel));
|
||||
TextChannel returnedChannel = (TextChannel) testUnit.handle(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertEquals(channel, returnedChannel);
|
||||
assertThat(returnedChannel).isEqualTo(channel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user