mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-20 21:29:08 +00:00
[AB-197] splitting utility maven module into separate maven modules
aligning some package names removing some unnecessary computed values from liquibase
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.entertainment.model.ChooseResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ChooseTest {
|
||||
|
||||
@InjectMocks
|
||||
private Choose testUnit;
|
||||
|
||||
@Mock
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ChooseResponseModel> responseModelArgumentCaptor;
|
||||
|
||||
@Test
|
||||
public void executeChooseCommand() {
|
||||
List<String> choices = Arrays.asList("choice1", "choice2");
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(choices));
|
||||
when(entertainmentService.takeChoice(choices, parameters.getAuthor())).thenReturn(choices.get(0));
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(Choose.CHOOSE_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(parameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
|
||||
Assert.assertEquals(choices.get(0), responseModelArgumentCaptor.getValue().getChosenValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.entertainment.model.EightBallResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EightBallTest {
|
||||
|
||||
@InjectMocks
|
||||
private EightBall testUnit;
|
||||
|
||||
@Mock
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<EightBallResponseModel> responseModelArgumentCaptor;
|
||||
|
||||
@Test
|
||||
public void execute8BallCommand() {
|
||||
String inputText = "text";
|
||||
String chosenKey = "key";
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(inputText));
|
||||
when(entertainmentService.getEightBallValue(inputText)).thenReturn(chosenKey);
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(EightBall.EIGHT_BALL_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(parameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
|
||||
Assert.assertEquals(chosenKey, responseModelArgumentCaptor.getValue().getChosenKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.entertainment.model.LoveCalcResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static dev.sheldan.abstracto.entertainment.command.LoveCalc.LOVE_CALC_RESPONSE_TEMPLATE_KEY;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LoveCalcTest {
|
||||
|
||||
@InjectMocks
|
||||
private LoveCalc testUnit;
|
||||
|
||||
@Mock
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<LoveCalcResponseModel> responseModelArgumentCaptor;
|
||||
|
||||
@Test
|
||||
public void execute8BallCommand() {
|
||||
String inputText = "text";
|
||||
String inputText2 = "text2";
|
||||
Integer loveResult = 2;
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(inputText, inputText2));
|
||||
when(entertainmentService.getLoveCalcValue(inputText, inputText2)).thenReturn(loveResult);
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(LOVE_CALC_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(parameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
|
||||
Assert.assertEquals(loveResult, responseModelArgumentCaptor.getValue().getRolled());
|
||||
Assert.assertEquals(inputText, responseModelArgumentCaptor.getValue().getFirstPart());
|
||||
Assert.assertEquals(inputText2, responseModelArgumentCaptor.getValue().getSecondPart());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.entertainment.model.RollResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static dev.sheldan.abstracto.entertainment.config.EntertainmentFeature.ROLL_DEFAULT_HIGH_KEY;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RollTest {
|
||||
|
||||
@InjectMocks
|
||||
private Roll testUnit;
|
||||
|
||||
@Mock
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Mock
|
||||
private ConfigService configService;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<RollResponseModel> responseModelArgumentCaptor;
|
||||
|
||||
@Test
|
||||
public void executeWithNoParameter() {
|
||||
CommandContext noParameters = CommandTestUtilities.getNoParameters();
|
||||
Integer result = 4;
|
||||
Long serverId = 3L;
|
||||
Integer max = 10;
|
||||
when(noParameters.getGuild().getIdLong()).thenReturn(serverId);
|
||||
when(configService.getLongValue(ROLL_DEFAULT_HIGH_KEY, serverId)).thenReturn(max.longValue());
|
||||
when(entertainmentService.calculateRollResult(1, max)).thenReturn(result);
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(Roll.ROLL_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> futureResult = testUnit.executeAsync(noParameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(futureResult);
|
||||
Assert.assertEquals(4, responseModelArgumentCaptor.getValue().getRolled().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeWithHighParameter() {
|
||||
CommandContext noParameters = CommandTestUtilities.getWithParameters(Arrays.asList(20));
|
||||
Integer result = 4;
|
||||
when(entertainmentService.calculateRollResult(1, 20)).thenReturn(result);
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(Roll.ROLL_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> futureResult = testUnit.executeAsync(noParameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(futureResult);
|
||||
Assert.assertEquals(4, responseModelArgumentCaptor.getValue().getRolled().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeWithBothParameters() {
|
||||
CommandContext noParameters = CommandTestUtilities.getWithParameters(Arrays.asList(20, 10));
|
||||
Integer result = 4;
|
||||
when(entertainmentService.calculateRollResult(10, 20)).thenReturn(result);
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(Roll.ROLL_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> futureResult = testUnit.executeAsync(noParameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(futureResult);
|
||||
Assert.assertEquals(4, responseModelArgumentCaptor.getValue().getRolled().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.entertainment.model.RouletteResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RouletteTest {
|
||||
|
||||
@InjectMocks
|
||||
private Roulette testUnit;
|
||||
|
||||
@Mock
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<RouletteResponseModel> responseModelArgumentCaptor;
|
||||
|
||||
@Test
|
||||
public void executeWithNoParameter() {
|
||||
CommandContext noParameters = CommandTestUtilities.getNoParameters();
|
||||
Boolean result = false;
|
||||
when(entertainmentService.executeRoulette(noParameters.getAuthor())).thenReturn(result);
|
||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(Roulette.ROULETTE_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||
CompletableFuture<CommandResult> futureResult = testUnit.executeAsync(noParameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(futureResult);
|
||||
Assert.assertEquals(result, responseModelArgumentCaptor.getValue().getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package dev.sheldan.abstracto.entertainment.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeature;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EntertainmentServiceBeanTest {
|
||||
@InjectMocks
|
||||
private EntertainmentServiceBean testUnit;
|
||||
|
||||
@Mock
|
||||
private SecureRandom secureRandom;
|
||||
|
||||
@Mock
|
||||
private ConfigService configService;
|
||||
|
||||
private static final String INPUT_TEXT = "input";
|
||||
private static final int RANDOM_VALUE = 0;
|
||||
|
||||
@Test
|
||||
public void testEightBallChoice() {
|
||||
when(secureRandom.nextInt(EntertainmentServiceBean.EIGHT_BALL_ANSWER_KEYS.size())).thenReturn(RANDOM_VALUE);
|
||||
String chosenKey = testUnit.getEightBallValue(INPUT_TEXT);
|
||||
Assert.assertEquals(EntertainmentServiceBean.EIGHT_BALL_ANSWER_KEYS.get(RANDOM_VALUE), chosenKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoveCalc() {
|
||||
when(secureRandom.nextInt(100)).thenReturn(RANDOM_VALUE);
|
||||
Integer loveCalcValue = testUnit.getLoveCalcValue(INPUT_TEXT, INPUT_TEXT);
|
||||
Assert.assertEquals(RANDOM_VALUE, loveCalcValue.intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoll() {
|
||||
executeRollTest(20, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollOutOfOrderParams() {
|
||||
executeRollTest(10, 20);
|
||||
}
|
||||
|
||||
private void executeRollTest(int high, int low) {
|
||||
when(secureRandom.nextInt(10)).thenReturn(RANDOM_VALUE);
|
||||
Integer loveCalcValue = testUnit.calculateRollResult(low, high);
|
||||
Assert.assertEquals(Math.min(low, high) + RANDOM_VALUE, loveCalcValue.intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouletteNoShot() {
|
||||
executeRouletteTest(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouletteShot() {
|
||||
executeRouletteTest(0);
|
||||
}
|
||||
|
||||
private void executeRouletteTest(int randomValue) {
|
||||
Long serverId = 3L;
|
||||
Member member = Mockito.mock(Member.class);
|
||||
Guild guild = Mockito.mock(Guild.class);
|
||||
when(guild.getIdLong()).thenReturn(serverId);
|
||||
when(member.getGuild()).thenReturn(guild);
|
||||
Long sides = 6L;
|
||||
when(configService.getLongValue(EntertainmentFeature.ROULETTE_BULLETS_CONFIG_KEY, serverId)).thenReturn(sides);
|
||||
when(secureRandom.nextInt(sides.intValue())).thenReturn(randomValue);
|
||||
boolean shot = testUnit.executeRoulette(member);
|
||||
Assert.assertEquals(randomValue == 0, shot);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTakeChoice(){
|
||||
Member member = Mockito.mock(Member.class);
|
||||
List<String> choices = Arrays.asList(INPUT_TEXT, INPUT_TEXT + "test");
|
||||
when(secureRandom.nextInt(choices.size())).thenReturn(RANDOM_VALUE);
|
||||
String choiceTaken = testUnit.takeChoice(choices, member);
|
||||
Assert.assertEquals(choices.get(0), choiceTaken);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user