Skip to main content
added 9 characters in body
Source Link
prem kumar
  • 5.9k
  • 3
  • 26
  • 39
@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(Matchers.any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:-

  • You got null because you did not set the expected return value. Actually connector.newGetWeatherDataCall() returns null. This is because you did not use Mockito.when() to return your expected results.
  • Second : In your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.
@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:-

  • You got null because you did not set the expected return value. Actually connector.newGetWeatherDataCall() returns null. This is because you did not use Mockito.when() to return your expected results.
  • Second : In your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.
@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(Matchers.any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:-

  • You got null because you did not set the expected return value. Actually connector.newGetWeatherDataCall() returns null. This is because you did not use Mockito.when() to return your expected results.
  • Second : In your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.
deleted 2 characters in body
Source Link
prem kumar
  • 5.9k
  • 3
  • 26
  • 39
@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:- You got null because you did not set the expected return value. Second ,in your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.

  • You got null because you did not set the expected return value. Actually connector.newGetWeatherDataCall() returns null. This is because you did not use Mockito.when() to return your expected results.
  • Second : In your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.
@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:- You got null because you did not set the expected return value. Second ,in your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.

@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:-

  • You got null because you did not set the expected return value. Actually connector.newGetWeatherDataCall() returns null. This is because you did not use Mockito.when() to return your expected results.
  • Second : In your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.
deleted 2 characters in body
Source Link
prem kumar
  • 5.9k
  • 3
  • 26
  • 39
@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:- You got null because you did not set the expected return value. Second that in this,in your case, a method on this return value is invoked so connector.newGetWeatherDataCall() willshould return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.

@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:- You got null because you did not set the expected return value. Second that in this case, a method on this return value is invoked so connector.newGetWeatherDataCall() will return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.

@Test public void getDataTest() { WeatherData getWeatherDataResponse = Mockito.mock(WeatherData.class); when(connector.newGetWeatherDataCall()).thenReturn(getWeatherDataResponse); when(getWeatherDataResponse.call(any(Class.class))).thenReturn(new ServiceData()); assertNotNull(service.getData("123")); } 

Explanation:- You got null because you did not set the expected return value. Second ,in your case, a method on this return value is invoked so connector.newGetWeatherDataCall() should return a mock of WeatherData. And now you will set an expectation for weatherData.call(..) which will be ServiceData type.

Source Link
prem kumar
  • 5.9k
  • 3
  • 26
  • 39
Loading