2828import java .util .concurrent .TimeUnit ;
2929import java .util .concurrent .TimeoutException ;
3030
31+ import static org .mockito .BDDMockito .given ;
3132import static org .springframework .test .web .servlet .ResultMatcher .matchAll ;
3233import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
3334import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
@@ -51,7 +52,7 @@ public void createReviewShouldReturnTheGivenReviewBack() throws Exception {
5152 Timestamp t = new Timestamp (10 );
5253 String time = getTimeStringFormatted (t );
5354 Review review = new Review (userId , "5" , 3.5F , t );
54-
55+ given ( kafkaTemplate . sendDefault ( "3,5,3.5,10" )). willReturn ( null );
5556 this .mockMvc .perform (post ("/users/" +userId +"/reviews" )
5657 .content (asJsonString (review ))
5758 .contentType (MediaType .APPLICATION_JSON_UTF8 )
@@ -83,47 +84,4 @@ public static String asJsonString(final Object obj) {
8384 throw new RuntimeException (e );
8485 }
8586 }
86-
87- @ Before
88- public void setUp () {
89- Mockito .when (kafkaTemplate .sendDefault ("3,5,3.5,10" )).thenReturn (new ListenableFuture <SendResult <String , String >>() {
90- @ Override
91- public void addCallback (ListenableFutureCallback <? super SendResult <String , String >> callback ) {
92-
93- }
94-
95- @ Override
96- public void addCallback (SuccessCallback <? super SendResult <String , String >> successCallback , FailureCallback failureCallback ) {
97-
98- }
99-
100- @ Override
101- public boolean cancel (boolean b ) {
102- return false ;
103- }
104-
105- @ Override
106- public boolean isCancelled () {
107- return false ;
108- }
109-
110- @ Override
111- public boolean isDone () {
112- return false ;
113- }
114-
115- @ Override
116- public SendResult <String , String > get () throws InterruptedException , ExecutionException {
117- return null ;
118- }
119-
120- @ Override
121- public SendResult <String , String > get (long l , TimeUnit timeUnit ) throws InterruptedException , ExecutionException , TimeoutException {
122- return null ;
123- }
124- });/*.then((Answer<String>) invocation -> {
125- System.out.println("3,5,3.5,10 -- printed");
126- return "Do nothing.";
127- });*/
128- }
12987}
0 commit comments