Serializing False Throw Exclusions

I am trying to test my controller using mockMvc and mockito. The actual controller case is as follows:

Message createXYZ(@RequestBody XYZ inst){
   //creates XYZ
}

Now for pushing values ​​through the request body, I create JSON using GsonBuilder, by serializing XYZ. Here is the structure for the XYZ class:

class XYZ{

  List<Y> listofYs;
  //some other properties as well
}

I create and set the layout for the ListYYY list, and when Gson tries to serialize an XYZ instance that has the mocked listofYs its generating NPE.

Is there a way or is it that I am doing this completely wrong?

+5
source share
2 answers

According to the Mockito documentation , you can make the layout serializable:

List serializableMock = mock(List.class, withSettings().serializable());
+9

, , , :

@Mock(serializable = true)
List serializableMock;
+1

Source: https://habr.com/ru/post/1544324/


All Articles