I am using MockMvc for the first type. What I am doing is testing a Restcontroller in SPringboot.
I have a Restcontroller like this,
@RequestMapping("/address")
public class AddressController {
@RequestMapping("/createAddress")
public Address craeteAddress(Address address)
{
Address add=addressService.createAdd(address);
return add;
}
@RequestMapping("/getAll")
public List<Address> getAll()
{
return addressService.getAll();
}
}
Now my test class looks like this,
public class AddressControllerTest {
AddressService addressService = mock(AddressService.class);
@Autowired
MockMvc mockMvc;
private static final String ADDRESS_DTO_JSON =
"{" +
"\"id\":\"123\"," +
"\"pacsId\":\"345\"," +
"}";
List<Object> object = new ArrayList<Object>();
@Before
public void setup() {
}
@Test
public void createAddressTest() throws Exception {
//System.out.println("The Json Content :" + ADDRESS_DTO_JSON);
this.mockMvc
.perform(get("address/getAll"))
.andExpect(status().isOk())
.andReturn();
}
}
I am trying to call the 'address/getAll' method in the restcontroller. When i run the junit method it says 'Null Pointer Exception' near the .perform(get("address/getAll")) line.
I did some research but did not work out. Can someone please help ?