-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing complete for repository interfaces
- Loading branch information
Daniel Villavicencio
authored and
Daniel Villavicencio
committed
Jan 31, 2024
1 parent
5f443d7
commit f5be655
Showing
6 changed files
with
205 additions
and
44 deletions.
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
src/test/java/com/danielvm/destiny2bot/repository/UserCharacterRepositoryImplTest.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,67 @@ | ||
package com.danielvm.destiny2bot.repository; | ||
|
||
import static com.danielvm.destiny2bot.repository.UserCharacterRepositoryImpl.INSERT_CHARACTER_QUERY; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.danielvm.destiny2bot.entity.UserCharacter; | ||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.r2dbc.core.DatabaseClient; | ||
import org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec; | ||
import org.springframework.r2dbc.core.RowsFetchSpec; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class UserCharacterRepositoryImplTest { | ||
|
||
@Mock | ||
private DatabaseClient databaseClient; | ||
|
||
@InjectMocks | ||
private UserCharacterRepositoryImpl sut; | ||
|
||
@Test | ||
@DisplayName("Save user character is successful") | ||
public void saveUserCharacterIsSuccessful() { | ||
// given: a user character to save | ||
UserCharacter userCharacter = new UserCharacter( | ||
1L, 1801, "Titan", 12345L); | ||
|
||
Map<String, Object> parameters = Map.of( | ||
"characterId", userCharacter.getCharacterId(), | ||
"lightLevel", userCharacter.getLightLevel(), | ||
"discordUserId", userCharacter.getDiscordUserId(), | ||
"destinyClass", userCharacter.getDestinyClass() | ||
); | ||
|
||
GenericExecuteSpec genericExecuteSpec = mock(GenericExecuteSpec.class); | ||
RowsFetchSpec<UserCharacter> rowsFetchSpec = mock(RowsFetchSpec.class); | ||
|
||
when(databaseClient.sql(INSERT_CHARACTER_QUERY)).thenReturn(genericExecuteSpec); | ||
when(genericExecuteSpec.bindValues(parameters)).thenReturn(genericExecuteSpec); | ||
when(genericExecuteSpec.map(any(BiFunction.class))).thenReturn(rowsFetchSpec); | ||
when(rowsFetchSpec.one()).thenReturn(Mono.just(userCharacter)); | ||
|
||
// when: save is called for a user character | ||
var result = StepVerifier.create(sut.save(userCharacter)); | ||
|
||
// then: the saved character is returned | ||
result.assertNext(user -> { | ||
assertThat(user.getDiscordUserId()).isEqualTo(userCharacter.getDiscordUserId()); | ||
assertThat(user.getCharacterId()).isEqualTo(userCharacter.getCharacterId()); | ||
assertThat(user.getLightLevel()).isEqualTo(userCharacter.getLightLevel()); | ||
assertThat(user.getDestinyClass()).isEqualTo(userCharacter.getDestinyClass()); | ||
}).verifyComplete(); | ||
} | ||
|
||
} |