@Test
public void testRemoveAuthenticationWithLogoutThrowable() throws Exception {

    final boolean[] invoked = new boolean[1];
    Broker broker = new BrokerPluginSupport() {
        @Override
        public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
            invoked[0] = true;
        }
    };
    DefaultEnvironment env = new DefaultEnvironment();
    filter.setNext(broker);
    filter.setEnvironment(env);
    Subject subject = new SubjectAdapter() {
        @Override
        public void logout() {
            throw new RuntimeException("Simulated failure.");
        }
    };
    ConnectionContext ctx = new ConnectionContext();
    ConnectionInfo info = new ConnectionInfo();
    SubjectConnectionReference conn = new SubjectConnectionReference(ctx, info, env, subject);
    SubjectSecurityContext ssc = new SubjectSecurityContext(conn);
    ctx.setSecurityContext(ssc);
    filter.removeConnection(ctx, info, null);
    assertTrue(invoked[0]);
}