test: add backend tests for various controllers and services #232
17 changed files with 416 additions and 0 deletions
|
@ -78,6 +78,32 @@ jobs:
|
|||
working-directory: ./backend
|
||||
run: gradle --stop
|
||||
|
||||
backend-test:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Backend Tests"
|
||||
needs: changed_files
|
||||
if: ${{ needs.changed_files.outputs.backend == 'true' || needs.changed_files.outputs.workflow == 'true' }}
|
||||
container:
|
||||
image: "cimg/openjdk:23.0-node"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
- name: "Cache Gradle dependencies"
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: gradle-${{ runner.os }}-${{ hashFiles('backend/**/*.java', 'backend/build.gradle.kts', 'backend/settings.gradle.kts') }}
|
||||
restore-keys: |
|
||||
gradle-${{ runner.os }}-
|
||||
- name: "Run backend tests"
|
||||
working-directory: ./backend
|
||||
run: ./gradlew test
|
||||
- name: "Stop Gradle"
|
||||
working-directory: ./backend
|
||||
run: ./gradlew --stop
|
||||
|
||||
validate-docker-frontend:
|
||||
runs-on: ubuntu-latest
|
||||
name: Docker frontend validation
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BlackJackGameControllerTest {
|
||||
@InjectMocks
|
||||
private BlackJackGameController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BlackJackServiceTest {
|
||||
@InjectMocks
|
||||
private BlackJackService blackJackService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceNotNull() {
|
||||
assertNotNull(blackJackService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package de.szut.casino.coinflip;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.InsufficientFundsException;
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import de.szut.casino.shared.service.BalanceService;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class CoinflipControllerTest {
|
||||
@Mock
|
||||
private UserService userService;
|
||||
@Mock
|
||||
private BalanceService balanceService;
|
||||
@Mock
|
||||
private CoinflipService coinflipService;
|
||||
@InjectMocks
|
||||
private CoinflipController coinflipController;
|
||||
|
||||
private UserEntity user;
|
||||
private CoinflipDto coinflipDto;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
user = new UserEntity();
|
||||
user.setBalance(BigDecimal.valueOf(100));
|
||||
coinflipDto = new CoinflipDto(BigDecimal.valueOf(10), CoinSide.HEAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCoinFlip_success() {
|
||||
when(userService.getCurrentUser()).thenReturn(Optional.of(user));
|
||||
when(balanceService.hasFunds(user, coinflipDto)).thenReturn(true);
|
||||
CoinflipResult result = new CoinflipResult(true, BigDecimal.valueOf(20), CoinSide.HEAD);
|
||||
when(coinflipService.play(user, coinflipDto)).thenReturn(result);
|
||||
|
||||
ResponseEntity<Object> response = coinflipController.coinFlip(coinflipDto);
|
||||
|
||||
assertEquals(200, response.getStatusCodeValue());
|
||||
assertEquals(result, response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCoinFlip_userNotFound() {
|
||||
when(userService.getCurrentUser()).thenReturn(Optional.empty());
|
||||
assertThrows(UserNotFoundException.class, () -> coinflipController.coinFlip(coinflipDto));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCoinFlip_insufficientFunds() {
|
||||
when(userService.getCurrentUser()).thenReturn(Optional.of(user));
|
||||
when(balanceService.hasFunds(user, coinflipDto)).thenReturn(false);
|
||||
assertThrows(InsufficientFundsException.class, () -> coinflipController.coinFlip(coinflipDto));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.deposit;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DepositControllerTest {
|
||||
@InjectMocks
|
||||
private DepositController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.deposit;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TransactionServiceTest {
|
||||
@InjectMocks
|
||||
private TransactionService transactionService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceNotNull() {
|
||||
assertNotNull(transactionService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.deposit;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class WebhookControllerTest {
|
||||
@InjectMocks
|
||||
private WebhookController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.dice;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DiceControllerTest {
|
||||
@InjectMocks
|
||||
private DiceController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.dice;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DiceServiceTest {
|
||||
@InjectMocks
|
||||
private DiceService diceService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceNotNull() {
|
||||
assertNotNull(diceService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.health;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class HealthControllerTest {
|
||||
@InjectMocks
|
||||
private HealthController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LootBoxServiceTest {
|
||||
@InjectMocks
|
||||
private LootBoxService lootBoxService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceNotNull() {
|
||||
assertNotNull(lootBoxService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.security;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AuthControllerTest {
|
||||
@InjectMocks
|
||||
private AuthController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.slots;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SlotControllerTest {
|
||||
@InjectMocks
|
||||
private SlotController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.slots;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SlotServiceTest {
|
||||
@InjectMocks
|
||||
private SlotService slotService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceNotNull() {
|
||||
assertNotNull(slotService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.user;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class UserControllerTest {
|
||||
@InjectMocks
|
||||
private UserController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testControllerNotNull() {
|
||||
assertNotNull(controller);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.user;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class UserServiceTest {
|
||||
@InjectMocks
|
||||
private UserService userService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceNotNull() {
|
||||
assertNotNull(userService);
|
||||
}
|
||||
}
|
Reference in a new issue