@Before
  public void setUp() {
    eventListener = new AuthorizationEventListener();

    service = mock(IdentificationAuthorizationService.class);
    when(service.isValid(INVALID_IDENTIFYING_TOKEN)).thenReturn(false);
    when(service.isValid(IDENTIFYING_TOKEN)).thenReturn(true);
    eventListener.setIdentificationAuthorizationService(service);

    gateway = mock(AuthorizationCommandGateway.class);
    eventListener.setCommandGateway(gateway);
    eventListener.setAddOnIdentity("1");

    identityContext =
        new IdentityContext(new TypeBasedAddOnIdentity(ADD_ON_TYPE, "1"), new NullUserIdentity());
  }
  @Test
  public void testInvalidIdentification() {
    CorrelationToken token = new CorrelationToken();

    eventListener.onEvent(
        new AuthorizationRequestedEvent(
            CHARGING_STATION_ID, INVALID_IDENTIFYING_TOKEN, identityContext),
        token);

    verify(service).isValid(INVALID_IDENTIFYING_TOKEN);

    final CommandMessage command =
        asCommandMessage(
                new DenyAuthorizationCommand(
                    CHARGING_STATION_ID, INVALID_IDENTIFYING_TOKEN, identityContext))
            .andMetaData(Collections.singletonMap(CorrelationToken.KEY, token));

    // because GenericCommandMessage doesn't implement 'equals' method we have to provide a
    // ArgumentMatcher to validate the argument
    verify(gateway)
        .send(
            argThat(
                new ArgumentMatcher<CommandMessage>() {
                  @Override
                  public boolean matches(Object o) {
                    if (!(o instanceof GenericCommandMessage)) {
                      return false;
                    }
                    GenericCommandMessage arg = (GenericCommandMessage) o;
                    return command.getMetaData().equals((arg).getMetaData())
                        && command.getPayload().equals((arg).getPayload());
                  }
                }));
  }
  @Test
  public void testNullCorrelationId() {
    eventListener.onEvent(
        new AuthorizationRequestedEvent(CHARGING_STATION_ID, IDENTIFYING_TOKEN, identityContext),
        null);

    verify(service).isValid(IDENTIFYING_TOKEN);

    // because GenericCommandMessage doesn't implement 'equals' method we have to provide a
    // ArgumentMatcher to validate the argument
    verify(gateway)
        .send(
            argThat(
                new ArgumentMatcher<CommandMessage>() {
                  @Override
                  public boolean matches(Object o) {
                    if (!(o instanceof GenericCommandMessage)) {
                      return false;
                    }
                    // just verify the meta data size
                    return ((GenericCommandMessage) o).getMetaData().size() == 0;
                  }
                }));
  }