### Question:
GrantPermissionJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), GrantPermissionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), GrantPermissionCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { GrantPermissionApiCommand command = gson.fromJson(commandObject, GrantPermissionApiCommand.class); Class commandClass = Class.forName(command.getCommandClass()); UserIdentity userIdentity = new SimpleUserIdentity(command.getUserIdentity()); commandGateway.send(new GrantPermissionCommand(csId, userIdentity, commandClass, identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Grant permission command not able to parse the payload, is your json correctly formatted?", ex); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Grant permission command cannot instantiate class object for command class, is the passed command class value a valid class?", e); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext);  }### Answer:
@Test public void handleGrantPermission() throws UserIdentityUnauthorizedException { JsonObject commandObject = gson.fromJson("{'commandClass': 'io.motown.domain.api.chargingstation.CreateChargingStationCommand', 'userIdentity': 'testUser'}", JsonObject.class); handler.handle(CHARGING_STATION_ID_STRING, commandObject, IDENTITY_CONTEXT); }
@Test public void handleGrantPermissionVerifyGatewayCall() throws UserIdentityUnauthorizedException { Class commandClass = CreateChargingStationCommand.class; String user = "testUser"; JsonObject commandObject = gson.fromJson("{'commandClass': '" + commandClass.getName() + "', 'userIdentity': '" + user + "'}", JsonObject.class); handler.handle(CHARGING_STATION_ID_STRING, commandObject, IDENTITY_CONTEXT); verify(gateway).send(new GrantPermissionCommand(new ChargingStationId(CHARGING_STATION_ID_STRING), new SimpleUserIdentity(user), commandClass, IDENTITY_CONTEXT)); }
@Test(expected = IllegalArgumentException.class) public void handleGrantPermissionInvalidCommandClass() throws UserIdentityUnauthorizedException { JsonObject commandObject = gson.fromJson("{'commandClass': 'io.motown.domain.api.chargingstation.NotExistingCommandClass', 'userIdentity': 'testUser'}", JsonObject.class); handler.handle(CHARGING_STATION_ID_STRING, commandObject, IDENTITY_CONTEXT); }