private CommandController mockCommandController() {
   CommandController cc = mock(CommandController.class);
   try {
     InteractionCommand mockCommand = mock(InteractionCommand.class);
     when(mockCommand.execute(any(InteractionContext.class))).thenReturn(Result.FAILURE);
     when(cc.fetchCommand("DO")).thenReturn(mockCommand);
     InteractionCommand mockCommand1 = mock(InteractionCommand.class);
     when(mockCommand1.execute(any(InteractionContext.class))).thenReturn(Result.FAILURE);
     when(cc.fetchCommand("GET")).thenReturn(mockCommand1);
   } catch (InteractionException ie) {
     Assert.fail(ie.getMessage());
   }
   return cc;
 }
  /*
   * This test is for a GET request where the command does not return a result.
   */
  @Test(expected = AssertionError.class)
  public void testGETCommandNoResultShouldFail() throws Exception {
    List<Action> actions = new ArrayList<Action>();
    actions.add(new Action("GET", Action.TYPE.VIEW));
    ResourceState initialState = new ResourceState("entity", "state", actions, "/path");

    // this test mocks a command that incorrectly returns no result
    InteractionCommand mockCommand = mock(InteractionCommand.class);

    // create mock command controller
    CommandController mockCommandController = mock(CommandController.class);
    when(mockCommandController.fetchCommand("GET")).thenReturn(mockCommand);

    // RIM with command controller that issues commands that always return SUCCESS
    HTTPHypermediaRIM rim =
        new HTTPHypermediaRIM(
            mockCommandController, new ResourceStateMachine(initialState), createMockMetadata());
    rim.get(mock(HttpHeaders.class), "id", mockEmptyUriInfo());
  }
  /*
   * This test is for a GET request where the command succeeds.
   * A successful GET command should set the requested resource onto
   * the InteractionContext.
   */
  public void testSuccessfulGETCommand() throws Exception {
    ResourceState initialState = new ResourceState("entity", "state", mockActions(), "/path");

    // this test incorrectly supplies a resource as a result of the command.
    InteractionCommand mockCommand =
        new InteractionCommand() {
          public Result execute(InteractionContext ctx) {
            ctx.setResource(new EntityResource<Object>());
            return Result.SUCCESS;
          }
        };

    // create mock command controller
    CommandController mockCommandController = mock(CommandController.class);
    when(mockCommandController.fetchCommand("DO")).thenReturn(mockCommand);

    // RIM with command controller that issues commands that always return SUCCESS
    HTTPHypermediaRIM rim =
        new HTTPHypermediaRIM(
            mockCommandController, new ResourceStateMachine(initialState), mock(Metadata.class));
    Response response = rim.get(mock(HttpHeaders.class), "id", mockEmptyUriInfo());
    assertNotNull(response.getEntity());
  }
 private CommandController mockCommandController(InteractionCommand mockCommand) {
   CommandController cc = mock(CommandController.class);
   when(cc.fetchCommand("DO")).thenReturn(mockCommand);
   when(cc.fetchCommand("GET")).thenReturn(mockCommand);
   return cc;
 }