-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
f49db25
commit 81b24fb
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/test/java/com/t3t/bookstoreapi/elastic/controller/AutocompleteControllerTest.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 com.t3t.bookstoreapi.elastic.controller; | ||
|
||
import com.t3t.bookstoreapi.elastic.service.AutocompleteService; | ||
import com.t3t.bookstoreapi.model.response.BaseResponse; | ||
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.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
class AutocompleteControllerTest { | ||
|
||
@Mock | ||
private AutocompleteService autocompleteService; | ||
|
||
@InjectMocks | ||
private AutocompleteController autocompleteController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void autocomplete_ReturnsExpectedResults() throws IOException { | ||
// Given | ||
String prefix = "test"; | ||
List<String> expectedData = Arrays.asList("example"); | ||
BaseResponse<List<String>> serviceResponse = new BaseResponse<>(); | ||
serviceResponse.setData(expectedData); | ||
|
||
when(autocompleteService.autocomplete(prefix)).thenReturn(serviceResponse); | ||
|
||
// When | ||
ResponseEntity<BaseResponse<List<String>>> response = autocompleteController.autocomplete(prefix); | ||
|
||
// Then | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertEquals(expectedData, response.getBody().getData()); | ||
} | ||
} |