@Test public void testGetCityForCode() { /** * We instantiate an object that we would like to be returned to StadiumFacade when the mocked * out CityService's method getStadiums is called. This will be a list of two StadiumModels. */ final CityModel cityModel = dummyDataCity(); // We tell Mockito we expect CityService's method getStadiumForCode to be // called, and that when it is, cityModel should be returned when(cityService.getCityForCode("TEST-CITY-CODE")).thenReturn(cityModel); doAnswer( new Answer<CityData>() { @Override public CityData answer(final InvocationOnMock invocation) throws Throwable { final Object[] args = invocation.getArguments(); if (args[1] instanceof CityData) { final CityData rd = (CityData) args[1]; rd.setName( "TEST-CITY-NAME-EN"); // assuming now emulating the value for Locale.ENGLISH rd.setCode("TEST-CITY-CODE"); } return null; } }) .when(this.cityPopulator) .populate( org.mockito.Matchers.any(CityModel.class), org.mockito.Matchers.any(CityData.class)); /** * We now make the call to StadiumFacade's getStadium. If within this method a call is made to * CityService's getStadium, Mockito will return the cityModel instance to it. Mockito will also * remember that the call was made. */ final CityData cityData = cityFacade.getCityForCode("TEST-CITY-CODE"); // Check that cityData is a correct DTO representation of the cityModel ServiceModel assertEquals(cityData.getName(), cityModel.getName(Locale.ENGLISH)); assertEquals(cityData.getCode(), cityModel.getCode()); }