-
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.
added jUnit tests with Mockito and added more checks for lambda methods
- Loading branch information
1 parent
afd6370
commit 400f990
Showing
185 changed files
with
34,320 additions
and
17 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
56 changes: 56 additions & 0 deletions
56
matcher/src/test/java/com/profile/matcher/assembler/PlayerAssemblerTest.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,56 @@ | ||
package com.profile.matcher.assembler; | ||
|
||
import com.profile.matcher.dto.player.ClanDto; | ||
import com.profile.matcher.dto.player.DeviceDto; | ||
import com.profile.matcher.entity.campaign.Campaign; | ||
import com.profile.matcher.entity.player.Clan; | ||
import com.profile.matcher.entity.player.Device; | ||
import com.profile.matcher.entity.player.Inventory; | ||
import com.profile.matcher.entity.player.Player; | ||
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 java.util.Collections; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class PlayerAssemblerTest { | ||
|
||
@InjectMocks | ||
private PlayerAssembler assembler; | ||
|
||
@Mock | ||
private DeviceAssembler deviceAssembler; | ||
@Mock | ||
private InventoryAssembler inventoryAssembler; | ||
@Mock | ||
private ClanAssembler clanAssembler; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
assembler = new PlayerAssembler(); | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
void toResourceTest() { | ||
Player player = new Player(); | ||
player.setClan(new Clan()); | ||
player.setDevices(Collections.singletonList(new Device())); | ||
player.setInventory(new Inventory()); | ||
Campaign campaign = new Campaign(); | ||
campaign.setName("mygame"); | ||
player.setCampaigns(Collections.singletonList(campaign)); | ||
|
||
when(deviceAssembler.toCollectionResource(player.getDevices())).thenReturn(Collections.singletonList(new DeviceDto())); | ||
when(inventoryAssembler.toResource(player.getInventory())).thenReturn(new HashMap<>(Collections.singletonMap("item_22", "34"))); | ||
when(clanAssembler.toResource(player.getClan())).thenReturn(new ClanDto()); | ||
|
||
assertNotNull(assembler.toResource(player)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
matcher/src/test/java/com/profile/matcher/command/PlayerCommandTest.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,36 @@ | ||
package com.profile.matcher.command; | ||
|
||
import com.profile.matcher.entity.player.Player; | ||
import com.profile.matcher.service.PlayerService; | ||
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 java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class PlayerCommandTest { | ||
@InjectMocks | ||
private PlayerCommand command; | ||
|
||
@Mock | ||
private PlayerService playerService; | ||
|
||
private final String idPlayer = "test"; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
command = new PlayerCommand(idPlayer); | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void doExecuteTest() { | ||
when(playerService.getPlayerDetails(idPlayer)).thenReturn(Optional.of(new Player())); | ||
assertNotNull(command.doExecute()); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
matcher/src/test/java/com/profile/matcher/controller/PlayerControllerTest.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,84 @@ | ||
package com.profile.matcher.controller; | ||
|
||
import com.profile.matcher.assembler.PlayerAssembler; | ||
import com.profile.matcher.command.PlayerCommand; | ||
import com.profile.matcher.dto.campaign.CampaignDto; | ||
import com.profile.matcher.dto.player.ClanDto; | ||
import com.profile.matcher.dto.player.DeviceDto; | ||
import com.profile.matcher.dto.player.PlayerDto; | ||
import com.profile.matcher.entity.campaign.Campaign; | ||
import com.profile.matcher.entity.player.Clan; | ||
import com.profile.matcher.entity.player.Device; | ||
import com.profile.matcher.entity.player.Inventory; | ||
import com.profile.matcher.entity.player.Player; | ||
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.beans.factory.BeanFactory; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class PlayerControllerTest { | ||
@InjectMocks | ||
private PlayerController controller; | ||
|
||
@Mock | ||
private PlayerAssembler playerAssembler; | ||
|
||
@Mock | ||
private PlayerCommand playerCommand; | ||
|
||
@Mock | ||
protected BeanFactory beanFactory; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
controller = new PlayerController(); | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void getClientConfigTest() { | ||
Player player = new Player(); | ||
player.setClan(new Clan()); | ||
player.setDevices(Collections.singletonList(new Device())); | ||
player.setInventory(new Inventory()); | ||
Campaign campaign = new Campaign(); | ||
campaign.setName("mygame"); | ||
player.setCampaigns(Collections.singletonList(campaign)); | ||
|
||
PlayerDto playerDto = new PlayerDto(); | ||
playerDto.setClan(new ClanDto()); | ||
playerDto.setDevices(Collections.singletonList(new DeviceDto())); | ||
playerDto.setInventory(Collections.singletonMap("item_22", "45")); | ||
CampaignDto campaignDto = new CampaignDto(); | ||
campaignDto.setName("mygame"); | ||
playerDto.setActive_campaigns(Collections.singletonList(campaignDto.getName())); | ||
|
||
when(beanFactory.getBean(PlayerCommand.class, "test")).thenReturn(playerCommand); | ||
when(playerCommand.execute()).thenReturn(Optional.of(player)); | ||
when(playerAssembler.toResource(player)).thenReturn(playerDto); | ||
|
||
ResponseEntity<PlayerDto> playerDtoResponseEntity = controller.getClientConfig("test"); | ||
assertNotNull(playerDtoResponseEntity); | ||
assertEquals(Objects.requireNonNull(playerDtoResponseEntity.getBody()).getActive_campaigns(), playerDto.getActive_campaigns()); | ||
} | ||
|
||
@Test | ||
public void getClientConfigTest_EmptyResponse() { | ||
when(beanFactory.getBean(PlayerCommand.class, "test")).thenReturn(playerCommand); | ||
when(playerCommand.execute()).thenReturn(Optional.empty()); | ||
|
||
ResponseEntity<PlayerDto> playerDtoResponseEntity = controller.getClientConfig("test"); | ||
assertNotNull(playerDtoResponseEntity); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
matcher/src/test/java/com/profile/matcher/service/CampaignServiceTest.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,39 @@ | ||
package com.profile.matcher.service; | ||
|
||
import com.profile.matcher.dto.campaign.CampaignDto; | ||
import com.profile.matcher.repository.CampaignRepository; | ||
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 java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class CampaignServiceTest { | ||
@InjectMocks | ||
private CampaignService service; | ||
|
||
@Mock | ||
private CampaignRepository campaignRepository; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
service = new CampaignService(); | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void getCurrentCampaignsMockedServiceTest() { | ||
List<CampaignDto> response = service.getCurrentCampaignsMockedService(); | ||
assertNotNull(response); | ||
} | ||
|
||
@Test | ||
public void getCurrentCampaignsRealServiceTest() { | ||
List<CampaignDto> response = service.getCurrentCampaignsRealService(); | ||
assertNotNull(response); | ||
} | ||
} |
Oops, something went wrong.