1818 */
1919package de .rwth .idsg .steve .web .api ;
2020
21- import de .rwth .idsg .steve .repository .TransactionRepository ;
2221import de .rwth .idsg .steve .repository .dto .Transaction ;
22+ import de .rwth .idsg .steve .service .TransactionService ;
2323import de .rwth .idsg .steve .web .dto .TransactionQueryForm ;
2424import org .joda .time .DateTime ;
2525import org .junit .jupiter .api .BeforeEach ;
5555public class TransactionRestControllerTest extends AbstractControllerTest {
5656
5757 @ Mock
58- private TransactionRepository transactionRepository ;
58+ private TransactionService transactionService ;
5959
6060 private MockMvc mockMvc ;
6161
6262 @ BeforeEach
6363 public void setup () {
64- mockMvc = MockMvcBuilders .standaloneSetup (new TransactionsRestController (transactionRepository ))
64+ mockMvc = MockMvcBuilders .standaloneSetup (new TransactionsRestController (transactionService ))
6565 .setControllerAdvice (new ApiControllerAdvice ())
6666 .setMessageConverters (new MappingJackson2HttpMessageConverter (objectMapper ))
6767 .alwaysExpect (content ().contentType ("application/json" ))
@@ -75,7 +75,7 @@ public void test1() throws Exception {
7575 List <Transaction > results = Collections .emptyList ();
7676
7777 // when
78- when (transactionRepository .getTransactions (any ())).thenReturn (results );
78+ when (transactionService .getTransactions (any ())).thenReturn (results );
7979
8080 // then
8181 mockMvc .perform (get ("/api/v1/transactions" ))
@@ -90,7 +90,7 @@ public void test2() throws Exception {
9090 List <Transaction > results = List .of (Transaction .builder ().id (234 ).build ());
9191
9292 // when
93- when (transactionRepository .getTransactions (any ())).thenReturn (results );
93+ when (transactionService .getTransactions (any ())).thenReturn (results );
9494
9595 // then
9696 mockMvc .perform (get ("/api/v1/transactions" ))
@@ -104,7 +104,7 @@ public void test2() throws Exception {
104104 @ DisplayName ("Downstream bean throws exception, expected 500" )
105105 public void test3 () throws Exception {
106106 // when
107- when (transactionRepository .getTransactions (any ())).thenThrow (new RuntimeException ("failed" ));
107+ when (transactionService .getTransactions (any ())).thenThrow (new RuntimeException ("failed" ));
108108
109109 // then
110110 mockMvc .perform (get ("/api/v1/transactions" ))
@@ -173,7 +173,7 @@ public void test8() throws Exception {
173173 .build ();
174174
175175 // when
176- when (transactionRepository .getTransactions (any ())).thenReturn (List .of (transaction ));
176+ when (transactionService .getTransactions (any ())).thenReturn (List .of (transaction ));
177177
178178 // then
179179 mockMvc .perform (get ("/api/v1/transactions" )
@@ -216,14 +216,14 @@ public void test10() throws Exception {
216216 ArgumentCaptor <TransactionQueryForm .TransactionQueryFormForApi > formToCapture = ArgumentCaptor .forClass (TransactionQueryForm .TransactionQueryFormForApi .class );
217217
218218 // when
219- when (transactionRepository .getTransactions (any ())).thenReturn (Collections .emptyList ());
219+ when (transactionService .getTransactions (any ())).thenReturn (Collections .emptyList ());
220220
221221 // then
222222 mockMvc .perform (get ("/api/v1/transactions" )
223223 .param ("type" , "ACTIVE" ))
224224 .andExpect (status ().isOk ());
225225
226- verify (transactionRepository ).getTransactions (formToCapture .capture ());
226+ verify (transactionService ).getTransactions (formToCapture .capture ());
227227 TransactionQueryForm .TransactionQueryFormForApi capturedForm = formToCapture .getValue ();
228228
229229 assertEquals (capturedForm .getType (), TransactionQueryForm .QueryType .ACTIVE );
@@ -237,14 +237,14 @@ public void test11() throws Exception {
237237 ArgumentCaptor <TransactionQueryForm .TransactionQueryFormForApi > formToCapture = ArgumentCaptor .forClass (TransactionQueryForm .TransactionQueryFormForApi .class );
238238
239239 // when
240- when (transactionRepository .getTransactions (any ())).thenReturn (Collections .emptyList ());
240+ when (transactionService .getTransactions (any ())).thenReturn (Collections .emptyList ());
241241
242242 // then
243243 mockMvc .perform (get ("/api/v1/transactions" )
244244 .param ("periodType" , "LAST_30" ))
245245 .andExpect (status ().isOk ());
246246
247- verify (transactionRepository ).getTransactions (formToCapture .capture ());
247+ verify (transactionService ).getTransactions (formToCapture .capture ());
248248 TransactionQueryForm .TransactionQueryFormForApi capturedForm = formToCapture .getValue ();
249249
250250 assertEquals (capturedForm .getType (), TransactionQueryForm .QueryType .ALL );
0 commit comments