-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AB-xxx] adding unit test for server controller
refactoring parameter parsing tests to use assertj
- Loading branch information
Showing
15 changed files
with
195 additions
and
116 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...ion/core/core-impl/src/test/java/dev/sheldan/abstracto/core/api/ServerControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.