-
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.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 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
72 changes: 72 additions & 0 deletions
72
challenge-service/src/test/java/com/cas/challengeservice/ChallengeControllerTests.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,72 @@ | ||
package com.cas.challengeservice; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.cas.challengeservice.controller.ChallengeController; | ||
import com.cas.challengeservice.dto.*; | ||
import com.cas.challengeservice.service.ChallengeService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
@SpringBootTest | ||
public class ChallengeControllerTests { | ||
@Mock private ChallengeService challengeService; | ||
@InjectMocks private ChallengeController challengeController; | ||
private Long userHeartRate; | ||
private String type; | ||
|
||
private GenericMessage<ChallengeTypeDto> message; | ||
private ChallengeGetRequest challengeGetRequest; | ||
private ChallengeAddRequest challengeAddRequest; | ||
private ChallengeDeleteRequest challengeDeleteRequest; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
userHeartRate = 70L; | ||
type = "Balance"; | ||
|
||
challengeGetRequest = new ChallengeGetRequest(userHeartRate, type); | ||
challengeAddRequest = new ChallengeAddRequest(); // add properties as necessary | ||
challengeDeleteRequest = new ChallengeDeleteRequest(); // add properties as necessary | ||
|
||
message = GenericMessage.<ChallengeTypeDto>builder().status(HttpStatus.OK).build(); | ||
} | ||
|
||
@Test | ||
public void testGetChallenge() { | ||
when(challengeService.getChallenge(any())).thenReturn(message); | ||
|
||
ResponseEntity<GenericMessage<ChallengeTypeDto>> responseEntity = | ||
challengeController.getChallenge(userHeartRate, type); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
verify(challengeService, times(1)).getChallenge(any()); | ||
} | ||
|
||
@Test | ||
public void testAddChallenge() { | ||
when(challengeService.addChallenge(any())).thenReturn(message); | ||
|
||
ResponseEntity<GenericMessage<ChallengeTypeDto>> responseEntity = | ||
challengeController.addChallenge(challengeAddRequest); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
verify(challengeService, times(1)).addChallenge(any()); | ||
} | ||
|
||
@Test | ||
public void testDeleteChallenge() { | ||
when(challengeService.deleteChallenge(any())).thenReturn(message); | ||
|
||
ResponseEntity<GenericMessage<ChallengeTypeDto>> responseEntity = | ||
challengeController.deleteChallenge(challengeDeleteRequest); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
verify(challengeService, times(1)).deleteChallenge(any()); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
challenge-service/src/test/java/com/cas/challengeservice/ChallengeServiceTests.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,4 @@ | ||
package com.cas.challengeservice; | ||
|
||
public class ChallengeServiceTests { | ||
} |