### Question:
CommandAuthorizationService { public boolean isAuthorized(ChargingStationId chargingStationId, UserIdentity userIdentity, Class commandClass) { boolean isAuthorized = commandAuthorizationRepository.find(chargingStationId.getId(), userIdentity.getId(), commandClass) != null; if (!isAuthorized) { isAuthorized = commandAuthorizationRepository.find(chargingStationId.getId(), userIdentity.getId(), AllPermissions.class) != null; } return isAuthorized; }  boolean isAuthorized(ChargingStationId chargingStationId, UserIdentity userIdentity, Class commandClass); void setCommandAuthorizationRepository(CommandAuthorizationRepository commandAuthorizationRepository);  }### Answer:
@Test public void isAuthorized() { when(commandAuthorizationRepository.find(CHARGING_STATION_ID.getId(), USER_IDENTITY.getId(), COMMAND_CLASS)).thenReturn(new CommandAuthorization(new CommandAuthorizationId(CHARGING_STATION_ID.getId(), USER_IDENTITY.getId(), AcceptChargingStationCommand.class))); assertTrue(commandAuthorizationService.isAuthorized(CHARGING_STATION_ID, USER_IDENTITY, COMMAND_CLASS)); }
@Test public void isAuthorizedAllPermissions() { when(commandAuthorizationRepository.find(CHARGING_STATION_ID.getId(), USER_IDENTITY.getId(), COMMAND_CLASS)).thenReturn(null); when(commandAuthorizationRepository.find(CHARGING_STATION_ID.getId(), USER_IDENTITY.getId(), AllPermissions.class)).thenReturn(new CommandAuthorization(new CommandAuthorizationId(CHARGING_STATION_ID.getId(), USER_IDENTITY.getId(), AllPermissions.class))); assertTrue(commandAuthorizationService.isAuthorized(CHARGING_STATION_ID, USER_IDENTITY, COMMAND_CLASS)); }
@Test public void isNotAuthorized() { when(commandAuthorizationRepository.find(CHARGING_STATION_ID.getId(), USER_IDENTITY.getId(), COMMAND_CLASS)).thenReturn(null); assertFalse(commandAuthorizationService.isAuthorized(CHARGING_STATION_ID, USER_IDENTITY, COMMAND_CLASS)); }