title: How to verify web responses when using Spring and test-mvc
body: <p>A question about how to use test-mvc for unit testing.</p>
  
  <p>I have a simple controller:</p>
  
  <pre><code>@Controller
  @RequestMapping("/users")
  public class UserController {        
      private UserService business;
      @Autowired
      public UserController(UserService bus)
      {
          business = bus;
      }
      @RequestMapping(value="{id}", method = RequestMethod.GET)
      public @ResponseBody User getUserById(@PathVariable String id) throws ItemNotFoundException{
  
          return business.GetUserById(id);
  
      }
  </code></pre>
  
  <p>(( My idea is to keep the controllers so thin as possible.))</p>
  
  <p>To test this controller I am trying to do something like this.</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = { "classpath:mvc-dispatcher-servlet.xml"})
  public class UserControllerTest extends ControllerTestBase {
  
  UserService mockedService;
  
  @Before
  public void Setup()
  {
  
      MockitoAnnotations.initMocks( this );   
      mockedService = mock(UserService.class);
  
  }
  
  @Test
  public void ReturnUserById() throws Exception{
  
      User user = new User();
      user.setName("Lasse");
  
      stub(mockedService.GetUserById("lasse")).toReturn(user);
  
      MockMvcBuilders.standaloneSetup(new UserController(mockedService)).build()
      .perform(get("/users/lasse"))
      .andExpect(status().isOk())
      .andExpect(?????????????????????????????);
  
  }
  </code></pre>
  
  <p>My intention is to check that proper json code is returned,,,,,, </p>
  
  <p>I am not a pro,,, so I have not found a way to replace ??????????????????????? with code to do verify the returned string but I am certain that there must be a elegant way to do this </p>
  
  <p>Can anyone fill me in?</p>
  
  <p>//lg</p>