[AB-8] upgrading to new JDA alpha version 19

cleaning up imports
This commit is contained in:
Sheldan
2022-09-18 15:51:49 +02:00
parent 102209aaca
commit 4e1f9e0018
216 changed files with 682 additions and 704 deletions

View File

@@ -4,23 +4,23 @@ import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
/**
* Container class for containing both an {@link Emote} and a {@link TrackedEmote} for the purpose of a {@link dev.sheldan.abstracto.core.command.config.Parameter}.
* Container class for containing both an {@link CustomEmoji} and a {@link TrackedEmote} for the purpose of a {@link dev.sheldan.abstracto.core.command.config.Parameter}.
* This is used in {@link dev.sheldan.abstracto.statistic.emote.command.TrackEmote} and is used as a convenience parameter, in which there
* might both a {@link Emote} and a {@link TrackedEmote} as parameter
* might both a {@link CustomEmoji} and a {@link TrackedEmote} as parameter
*/
@Getter
@Setter
@Builder
public class TrackEmoteParameter {
/**
* If an {@link Emote} has been used as parameter, this will have the appropriate value
* If an {@link CustomEmoji} has been used as parameter, this will have the appropriate value
*/
private Emote emote;
private CustomEmoji emote;
/**
* If a {@link Long} or {@link Emote} has been supplied as the parameter, this will contain a faked instance of the respective values
* If a {@link Long} or {@link CustomEmoji} has been supplied as the parameter, this will contain a faked instance of the respective values
*/
private TrackedEmote trackedEmote;
}

View File

@@ -10,8 +10,8 @@ import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler
import dev.sheldan.abstracto.core.command.service.CommandService;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -44,7 +44,7 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
/**
* This will parse the input for potential {@link TrackedEmote} and return a fake instance of such.
* At first it will see if there are any {@link Emote} directly in the message. If there are none at the current position
* At first it will see if there are any {@link CustomEmoji} directly in the message. If there are none at the current position
* it will try to parse the parameter to a {@link Long}. It is *not* guaranteed that a {@link TrackedEmote} with this ID
* really exists for this server. So, any commands using this are required to do checks on their own.
* @param input The {@link String} input at the current position
@@ -59,8 +59,8 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
@Override
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Parameter param, Message context, Command command) {
Parameter cloned = commandService.cloneParameter(param);
cloned.setType(Emote.class);
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, cloned, context, command);
cloned.setType(CustomEmoji.class);
CustomEmoji emote = (CustomEmoji) emoteParameterHandler.handle(input, iterators, cloned, context, command);
if(emote != null) {
return trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild());
} else {

View File

@@ -11,16 +11,16 @@ import dev.sheldan.abstracto.core.command.service.CommandService;
import dev.sheldan.abstracto.statistic.emote.command.parameter.TrackEmoteParameter;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* {@link CommandParameterHandler} for the {@link TrackEmoteParameter} class. It will call the
* {@link EmoteParameterHandler} and use the returned {@link Emote} if one is available. Otherwise it will only use the
* {@link EmoteParameterHandler} and use the returned {@link CustomEmoji} if one is available. Otherwise it will only use the
* {@link Long} which was passed. This handler will create a fake instance for the {@link dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote}
* and only make the {@link Emote} available in the result, if it was passed as such. This handler has a slightly higher priority
* and only make the {@link CustomEmoji} available in the result, if it was passed as such. This handler has a slightly higher priority
* than medium.
*/
@Component
@@ -47,8 +47,8 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
}
/**
* This tries to parse the input and extract an {@link Emote} or just an {@link Long}. It uses a {@link EmoteParameterHandler} at first,
* and if nothing is found tries to parse the {@link Long} directly from the input. In case an {@link Emote} was used, this will populate the
* This tries to parse the input and extract an {@link CustomEmoji} or just an {@link Long}. It uses a {@link EmoteParameterHandler} at first,
* and if nothing is found tries to parse the {@link Long} directly from the input. In case an {@link CustomEmoji} was used, this will populate the
* respective member variable in {@link TrackEmoteParameter}.
* @param input The {@link String} input at the current position
* @param iterators The {@link CommandParameterIterators} containing all available iterators to directly retrieve JDA related
@@ -56,15 +56,15 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
* @param param The {@link Class} which this type should handle
* @param context The {@link Message} which caused the command to be executed
* @param command
* @return An instance of {@link TrackEmoteParameter} which contains the available instances. This is an {@link Emote} in case it was
* @return An instance of {@link TrackEmoteParameter} which contains the available instances. This is an {@link CustomEmoji} in case it was
* used directly. In every successful case, it will contain a faked {@link TrackedEmote}.
*/
@Override
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Parameter param, Message context, Command command) {
TrackEmoteParameter parameter = TrackEmoteParameter.builder().build();
Parameter cloned = commandService.cloneParameter(param);
cloned.setType(Emote.class);
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, cloned, context, command);
cloned.setType(CustomEmoji.class);
CustomEmoji emote = (CustomEmoji) emoteParameterHandler.handle(input, iterators, cloned, context, command);
if(emote != null) {
parameter.setEmote(emote);
parameter.setTrackedEmote(trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild()));

View File

@@ -6,8 +6,8 @@ import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResult;
import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResultDisplay;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -15,7 +15,7 @@ import java.util.List;
/**
* Component to convert from a {@link EmoteStatsResult} to a proper instance of {@link EmoteStatsModel}.
* This for example loads the relevant {@link Emote} to be used within the model and also splits it up
* This for example loads the relevant {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} to be used within the model and also splits it up
* into static and animated emotes
*/
@Component
@@ -53,10 +53,10 @@ public class EmoteStatsConverter {
private EmoteStatsResultDisplay convertEmoteStatsResult(Guild relevantGuild, EmoteStatsResult emoteStatsResult) {
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByEmoteId(emoteStatsResult.getEmoteId(), emoteStatsResult.getServerId());
Emote loadedEmote = null;
CustomEmoji loadedEmote = null;
// if the emote should still exist, we try to load it
if(!trackedEmote.getExternal() && !trackedEmote.getDeleted()) {
loadedEmote = relevantGuild.getEmoteById(trackedEmote.getTrackedEmoteId().getId());
loadedEmote = relevantGuild.getEmojiById(trackedEmote.getTrackedEmoteId().getId());
}
return EmoteStatsResultDisplay
.builder()

View File

@@ -9,7 +9,6 @@ import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
import dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingMode;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Emote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,7 +16,7 @@ import java.util.Arrays;
import java.util.List;
/**
* This listener listens for created {@link Emote} in a {@link net.dv8tion.jda.api.entities.Guild} and creates appropriate
* This listener listens for created {@link net.dv8tion.jda.api.entities.emoji.RichCustomEmoji} in a {@link net.dv8tion.jda.api.entities.Guild} and creates appropriate
* {@link dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote}, if the EMOTE_TRACKING feature is enabled and the AUTO_TRACK
* feature mode as well.
*/

View File

@@ -9,7 +9,6 @@ import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
import dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingMode;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Emote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,7 +16,7 @@ import java.util.Arrays;
import java.util.List;
/**
* This listener listens for deleted {@link Emote} in a {@link net.dv8tion.jda.api.entities.Guild} and marks respective
* This listener listens for deleted {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} in a {@link net.dv8tion.jda.api.entities.Guild} and marks respective
* {@link dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote} as deleted, if the EMOTE_TRACKING feature is enabled and the AUTO_TRACK
* feature mode as well.
*/

View File

@@ -7,8 +7,8 @@ import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
import dev.sheldan.abstracto.core.service.GuildService;
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -40,11 +40,11 @@ public class EmoteTrackingListener implements AsyncMessageReceivedListener {
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
return DefaultListenerResult.IGNORED;
}
Map<Long, List<Emote>> collect = message
Map<Long, List<CustomEmoji>> collect = message
.getMentions()
.getEmotesBag()
.getCustomEmojisBag()
.stream()
.collect(Collectors.groupingBy(Emote::getIdLong));
.collect(Collectors.groupingBy(CustomEmoji::getIdLong));
collect.values().forEach(groupedEmotes ->
trackedEmoteService.addEmoteToRuntimeStorage(groupedEmotes.get(0), guildService.getGuildById(model.getServerId()), (long) groupedEmotes.size())
);

View File

@@ -18,8 +18,9 @@ import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmote;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import dev.sheldan.abstracto.statistic.emote.service.management.UsedEmoteManagementService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -87,7 +88,7 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
}
@Override
public void addEmoteToRuntimeStorage(Emote emote, Guild guild, Long count) {
public void addEmoteToRuntimeStorage(CustomEmoji emote, Guild guild, Long count) {
addEmoteToRuntimeStorage(cacheEntityService.getCachedEmoteFromEmote(emote, guild), guild, count);
}
@@ -141,7 +142,7 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
}
@Override
public TrackedEmote getFakeTrackedEmote(Emote emote, Guild guild) {
public TrackedEmote getFakeTrackedEmote(CustomEmoji emote, Guild guild) {
return getFakeTrackedEmote(emote.getIdLong(), guild);
}
@@ -158,10 +159,10 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
public TrackedEmoteSynchronizationResult synchronizeTrackedEmotes(Guild guild) {
List<TrackedEmote> activeTrackedEmotes = trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(guild.getIdLong());
Long addedEmotes = 0L;
List<Emote> allExistingEmotes = guild.getEmotes();
List<RichCustomEmoji> allExistingEmotes = guild.getEmojis();
log.info("Synchronizing emotes for server {}, currently tracked emotes {}, available emotes for server {}.", guild.getIdLong(), activeTrackedEmotes.size(), allExistingEmotes.size());
// iterate over all emotes currently available in the guild
for (Emote emote : allExistingEmotes) {
for (RichCustomEmoji emote : allExistingEmotes) {
// find the emote in the list of known TrackedEmote
Optional<TrackedEmote> trackedEmoteOptional = activeTrackedEmotes
.stream()
@@ -206,13 +207,13 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
}
@Override
public TrackedEmote createTrackedEmote(Emote emote, Guild guild) {
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild) {
boolean external = !emoteService.emoteIsFromGuild(emote, guild);
return createTrackedEmote(emote, guild, external);
}
@Override
public TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external) {
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild, boolean external) {
return trackedEmoteManagementService.createTrackedEmote(emote, guild, external);
}

View File

@@ -9,8 +9,9 @@ import dev.sheldan.abstracto.statistic.emote.model.PersistingEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.repository.TrackedEmoteRepository;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -33,13 +34,13 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
}
@Override
public TrackedEmote createTrackedEmote(Emote emote, Guild guild) {
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild) {
AServer server = serverManagementService.loadServer(guild.getIdLong());
return createTrackedEmote(emote.getIdLong(), emote.getName(), emote.isAnimated(), true, server);
}
@Override
public TrackedEmote createTrackedEmote(Emote emote) {
public TrackedEmote createTrackedEmote(RichCustomEmoji emote) {
return createTrackedEmote(emote, emote.getGuild());
}
@@ -50,7 +51,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
}
@Override
public TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external) {
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild, boolean external) {
if(external) {
return createExternalTrackedEmote(emote, guild);
} else {
@@ -103,7 +104,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
}
@Override
public TrackedEmote createExternalTrackedEmote(Emote emote, Guild guild) {
public TrackedEmote createExternalTrackedEmote(CustomEmoji emote, Guild guild) {
AServer server = serverManagementService.loadServer(guild.getIdLong());
return createExternalEmote(emote.getIdLong(), emote.getName(), emote.getImageUrl(), emote.isAnimated(), server, true);
}
@@ -115,7 +116,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
}
@Override
public void markAsDeleted(Emote emote) {
public void markAsDeleted(RichCustomEmoji emote) {
markAsDeleted(emote.getGuild().getIdLong(), emote.getIdLong());
}
@@ -131,7 +132,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
}
@Override
public TrackedEmote loadByEmote(Emote emote) {
public TrackedEmote loadByEmote(RichCustomEmoji emote) {
return loadByEmoteId(emote.getIdLong(), emote.getGuild().getIdLong());
}

View File

@@ -24,7 +24,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,8 +31,6 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import static dev.sheldan.abstracto.statistic.emote.command.ExportEmoteStats.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)

View File

@@ -24,8 +24,6 @@ import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import static dev.sheldan.abstracto.statistic.emote.command.ShowTrackedEmotes.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)

View File

@@ -15,7 +15,7 @@ import dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingMode;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -73,7 +73,7 @@ public class TrackEmoteTest {
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
Emote emoteToTrack = Mockito.mock(Emote.class);
CustomEmoji emoteToTrack = Mockito.mock(CustomEmoji.class);
when(trackEmoteParameter.getEmote()).thenReturn(emoteToTrack);
when(trackEmoteParameter.getTrackedEmote()).thenReturn(trackedEmote);
when(emoteService.emoteIsFromGuild(emoteToTrack, commandContext.getGuild())).thenReturn(false);
@@ -88,7 +88,7 @@ public class TrackEmoteTest {
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
Emote emoteToTrack = Mockito.mock(Emote.class);
CustomEmoji emoteToTrack = Mockito.mock(CustomEmoji.class);
when(trackEmoteParameter.getEmote()).thenReturn(emoteToTrack);
when(trackEmoteParameter.getTrackedEmote()).thenReturn(trackedEmote);
when(emoteService.emoteIsFromGuild(emoteToTrack, commandContext.getGuild())).thenReturn(false);

View File

@@ -10,9 +10,9 @@ import dev.sheldan.abstracto.core.command.service.CommandService;
import dev.sheldan.abstracto.statistic.emote.command.parameter.handler.TrackedEmoteParameterHandler;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
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;
@@ -78,7 +78,7 @@ public class TrackedEmoteParameterHandlerTest {
@Test
public void testHandleWithEmote() {
when(contextMessage.getGuild()).thenReturn(guild);
Emote emote = Mockito.mock(Emote.class);
RichCustomEmoji emote = Mockito.mock(RichCustomEmoji.class);
UnparsedCommandParameterPiece input = Mockito.mock(UnparsedCommandParameterPiece.class);
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
when(emoteParameterHandler.handle(input, iterators, parameter2, contextMessage, command)).thenReturn(emote);
@@ -97,7 +97,7 @@ public class TrackedEmoteParameterHandlerTest {
when(trackedEmoteService.getFakeTrackedEmote(emoteId, guild)).thenReturn(trackedEmote);
when(emoteParameterHandler.handle(input, iterators, parameter2, contextMessage, command)).thenReturn(null);
TrackedEmote parsedEmote = (TrackedEmote) testUnit.handle(input, iterators, parameter, contextMessage, command);
verify(trackedEmoteService, times(0)).getFakeTrackedEmote(any(Emote.class), eq(guild));
verify(trackedEmoteService, times(0)).getFakeTrackedEmote(any(RichCustomEmoji.class), eq(guild));
Assert.assertEquals(trackedEmote, parsedEmote);
}

View File

@@ -11,9 +11,9 @@ import dev.sheldan.abstracto.statistic.emote.command.parameter.TrackEmoteParamet
import dev.sheldan.abstracto.statistic.emote.command.parameter.handler.TrackedEmoteParameterParameterHandler;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
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;
@@ -22,8 +22,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
@@ -81,7 +79,7 @@ public class TrackedEmoteParameterParameterHandlerTest {
@Test
public void testHandleWithEmote() {
when(contextMessage.getGuild()).thenReturn(guild);
Emote emote = Mockito.mock(Emote.class);
RichCustomEmoji emote = Mockito.mock(RichCustomEmoji.class);
UnparsedCommandParameterPiece input = Mockito.mock(UnparsedCommandParameterPiece.class);
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
when(emoteParameterHandler.handle(input, iterators, parameter2, contextMessage, command)).thenReturn(emote);
@@ -101,7 +99,7 @@ public class TrackedEmoteParameterParameterHandlerTest {
when(commandService.cloneParameter(parameter)).thenReturn(parameter2);
when(emoteParameterHandler.handle(input, iterators, parameter2, contextMessage, command)).thenReturn(null);
TrackEmoteParameter parsedEmote = (TrackEmoteParameter) testUnit.handle(input, iterators, parameter, contextMessage, command);
verify(trackedEmoteService, times(0)).getFakeTrackedEmote(any(Emote.class), eq(guild));
verify(trackedEmoteService, times(0)).getFakeTrackedEmote(any(RichCustomEmoji.class), eq(guild));
Assert.assertEquals(trackedEmote, parsedEmote.getTrackedEmote());
}

View File

@@ -6,8 +6,8 @@ import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsModel;
import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResult;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -90,10 +90,10 @@ public class EmoteStatsConverterTest {
when(trackedEmote2.getDeleted()).thenReturn(false);
when(trackedEmote2.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID_2));
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
Emote emote1 = Mockito.mock(Emote.class);
when(guild.getEmoteById(EMOTE_ID)).thenReturn(emote1);
Emote emote2 = Mockito.mock(Emote.class);
when(guild.getEmoteById(EMOTE_ID_2)).thenReturn(emote2);
RichCustomEmoji emote1 = Mockito.mock(RichCustomEmoji.class);
when(guild.getEmojiById(EMOTE_ID)).thenReturn(emote1);
RichCustomEmoji emote2 = Mockito.mock(RichCustomEmoji.class);
when(guild.getEmojiById(EMOTE_ID_2)).thenReturn(emote2);
EmoteStatsModel result = testUnit.fromEmoteStatsResults(Arrays.asList(emoteStatsResult, emoteStatsResult2));
Assert.assertEquals(1, result.getStaticEmotes().size());

View File

@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.statistic.emote.listener;
import dev.sheldan.abstracto.core.models.listener.EmoteCreatedModel;
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,7 +31,7 @@ public class CreateTrackedEmoteListenerTest {
@Test
public void testEmoteCreated() {
Emote emote = Mockito.mock(Emote.class);
RichCustomEmoji emote = Mockito.mock(RichCustomEmoji.class);
when(emote.getIdLong()).thenReturn(EMOTE_ID);
when(model.getEmote()).thenReturn(emote);
when(model.getServerId()).thenReturn(SERVER_ID);

View File

@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.statistic.emote.listener;
import dev.sheldan.abstracto.core.models.listener.EmoteDeletedModel;
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,7 +28,7 @@ public class DeleteTrackedEmoteListenerTest {
@Test
public void testEmoteDeleted() {
Emote emote = Mockito.mock(Emote.class);
RichCustomEmoji emote = Mockito.mock(RichCustomEmoji.class);
when(model.getEmote()).thenReturn(emote);
testUnit.execute(model);
verify(trackedEmoteManagementService, times(1)).markAsDeleted(emote);

View File

@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.models.listener.EmoteNameUpdatedModel;
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,7 +29,7 @@ public class UpdateTrackedEmoteListenerTest {
@Test
public void testEmoteUpdated() {
Emote changedEmote = Mockito.mock(Emote.class);
RichCustomEmoji changedEmote = Mockito.mock(RichCustomEmoji.class);
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
when(trackedEmoteManagementService.loadByEmote(changedEmote)).thenReturn(trackedEmote);
String newValue = "AFTER";

View File

@@ -15,8 +15,9 @@ import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmote;
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
import dev.sheldan.abstracto.statistic.emote.service.management.UsedEmoteManagementService;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
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;
@@ -66,10 +67,10 @@ public class TrackedEmoteServiceBeanTest {
private CachedEmote secondEmote;
@Mock
private Emote actualEmote;
private RichCustomEmoji actualEmote;
@Mock
private Emote secondActualEmote;
private RichCustomEmoji secondActualEmote;
@Mock
private Guild guild;
@@ -230,14 +231,14 @@ public class TrackedEmoteServiceBeanTest {
when(secondTrackedEmote.getTrackedEmoteId()).thenReturn(secondTrackedEmoteServer);
when(secondTrackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
when(secondTrackedEmoteServer.getId()).thenReturn(EMOTE_ID_2);
when(guild.getEmotes()).thenReturn(Arrays.asList(actualEmote, secondActualEmote));
when(guild.getEmojis()).thenReturn(Arrays.asList(actualEmote, secondActualEmote));
when(actualEmote.getIdLong()).thenReturn(EMOTE_ID);
when(secondActualEmote.getIdLong()).thenReturn(EMOTE_ID_2);
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>(Arrays.asList(trackedEmote, secondTrackedEmote)));
TrackedEmoteSynchronizationResult result = testUnit.synchronizeTrackedEmotes(guild);
Assert.assertEquals(0L, result.getEmotesAdded().longValue());
Assert.assertEquals(0L, result.getEmotesMarkedDeleted().longValue());
verify(trackedEmoteManagementService, times(0)).createTrackedEmote(any(Emote.class), any(Guild.class));
verify(trackedEmoteManagementService, times(0)).createTrackedEmote(any(CustomEmoji.class), any(Guild.class));
verify(trackedEmoteManagementService, times(0)).markAsDeleted(any(TrackedEmote.class));
}
@@ -247,7 +248,7 @@ public class TrackedEmoteServiceBeanTest {
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
when(trackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
when(trackedEmoteServer.getId()).thenReturn(EMOTE_ID);
when(guild.getEmotes()).thenReturn(Arrays.asList(actualEmote, secondActualEmote));
when(guild.getEmojis()).thenReturn(Arrays.asList(actualEmote, secondActualEmote));
when(actualEmote.getIdLong()).thenReturn(EMOTE_ID);
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>(Arrays.asList(trackedEmote)));
TrackedEmoteSynchronizationResult result = testUnit.synchronizeTrackedEmotes(guild);
@@ -263,37 +264,37 @@ public class TrackedEmoteServiceBeanTest {
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
when(trackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
when(trackedEmoteServer.getId()).thenReturn(EMOTE_ID);
when(guild.getEmotes()).thenReturn(Arrays.asList(actualEmote));
when(guild.getEmojis()).thenReturn(Arrays.asList(actualEmote));
when(actualEmote.getIdLong()).thenReturn(EMOTE_ID);
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>(Arrays.asList(trackedEmote, secondTrackedEmote)));
TrackedEmoteSynchronizationResult result = testUnit.synchronizeTrackedEmotes(guild);
Assert.assertEquals(0L, result.getEmotesAdded().longValue());
Assert.assertEquals(1L, result.getEmotesMarkedDeleted().longValue());
verify(trackedEmoteManagementService, times(0)).createTrackedEmote(any(Emote.class), any(Guild.class));
verify(trackedEmoteManagementService, times(0)).createTrackedEmote(any(CustomEmoji.class), any(Guild.class));
verify(trackedEmoteManagementService, times(1)).markAsDeleted(secondTrackedEmote);
}
@Test
public void testSynchronizeTrackedEmotesNoEmotesLeft() {
when(guild.getIdLong()).thenReturn(SERVER_ID);
when(guild.getEmotes()).thenReturn(new ArrayList<>());
when(guild.getEmojis()).thenReturn(new ArrayList<>());
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>(Arrays.asList(trackedEmote, secondTrackedEmote)));
TrackedEmoteSynchronizationResult result = testUnit.synchronizeTrackedEmotes(guild);
Assert.assertEquals(0L, result.getEmotesAdded().longValue());
Assert.assertEquals(2L, result.getEmotesMarkedDeleted().longValue());
verify(trackedEmoteManagementService, times(0)).createTrackedEmote(any(Emote.class), any(Guild.class));
verify(trackedEmoteManagementService, times(0)).createTrackedEmote(any(CustomEmoji.class), any(Guild.class));
verify(trackedEmoteManagementService, times(2)).markAsDeleted(any(TrackedEmote.class));
}
@Test
public void testSynchronizeTrackedEmotesAllEmotesAreNew() {
when(guild.getIdLong()).thenReturn(SERVER_ID);
when(guild.getEmotes()).thenReturn(Arrays.asList(actualEmote, secondActualEmote));
when(guild.getEmojis()).thenReturn(Arrays.asList(actualEmote, secondActualEmote));
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>());
TrackedEmoteSynchronizationResult result = testUnit.synchronizeTrackedEmotes(guild);
Assert.assertEquals(2L, result.getEmotesAdded().longValue());
Assert.assertEquals(0L, result.getEmotesMarkedDeleted().longValue());
verify(trackedEmoteManagementService, times(2)).createTrackedEmote(any(Emote.class), any(Guild.class));
verify(trackedEmoteManagementService, times(2)).createTrackedEmote(any(CustomEmoji.class), any(Guild.class));
verify(trackedEmoteManagementService, times(0)).markAsDeleted(any(TrackedEmote.class));
}
@@ -483,9 +484,9 @@ public class TrackedEmoteServiceBeanTest {
when(trackedEmote2.getAnimated()).thenReturn(true);
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
when(trackedEmote2.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID_2));
when(guild.getEmoteById(EMOTE_ID)).thenReturn(actualEmote);
Emote emote2 = Mockito.mock(Emote.class);
when(guild.getEmoteById(EMOTE_ID_2)).thenReturn(emote2);
when(guild.getEmojiById(EMOTE_ID)).thenReturn(actualEmote);
RichCustomEmoji emote2 = Mockito.mock(RichCustomEmoji.class);
when(guild.getEmojiById(EMOTE_ID_2)).thenReturn(emote2);
when(trackedEmoteManagementService.getTrackedEmoteForServer(SERVER_ID, true)).thenReturn(Arrays.asList(trackedEmote, trackedEmote2));
TrackedEmoteOverview trackedEmoteOverview = testUnit.loadTrackedEmoteOverview(guild, true);
Assert.assertEquals(actualEmote, trackedEmoteOverview.getStaticEmotes().get(0).getEmote());

View File

@@ -19,8 +19,6 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)

View File

@@ -7,8 +7,8 @@ import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.statistic.emote.model.PersistingEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.repository.TrackedEmoteRepository;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,7 +40,7 @@ public class TrackedEmoteManagementServiceBeanTest {
private ServerManagementService serverManagementService;
@Mock
private Emote emote;
private RichCustomEmoji emote;
@Mock
private Guild guild;