### Question:
AuthenticationInterceptor implements ServerInterceptor { @Override public <T, R> ServerCall.Listener<T> interceptCall(ServerCall<T, R> serverCall, Metadata metadata, ServerCallHandler<T, R> serverCallHandler) { String token = metadata.get(GrpcMetadataKeys.TOKEN_KEY); StatusRuntimeException sre = null; String context = GrpcMetadataKeys.CONTEXT_KEY.get(); if( token == null) { token = metadata.get(GrpcMetadataKeys.AXONDB_TOKEN_KEY); } if( context == null) { context = metadata.get(GrpcMetadataKeys.AXONDB_CONTEXT_MD_KEY); } if (token == null) { sre = GrpcExceptionBuilder.build(ErrorCode.AUTHENTICATION_TOKEN_MISSING, "No token for " + serverCall.getMethodDescriptor().getFullMethodName()); } else if (!axonServerAccessController.allowed(serverCall.getMethodDescriptor().getFullMethodName(), context, token)) { sre = GrpcExceptionBuilder.build(ErrorCode.AUTHENTICATION_INVALID_TOKEN, "Invalid token for " + serverCall.getMethodDescriptor().getFullMethodName()); } if( sre != null) { serverCall.close(sre.getStatus(), sre.getTrailers()); return new ServerCall.Listener<T>() {}; } Context updatedGrpcContext = Context.current().withValue(GrpcMetadataKeys.TOKEN_CONTEXT_KEY, token); return Contexts.interceptCall(updatedGrpcContext, serverCall, metadata, serverCallHandler); } AuthenticationInterceptor(AxonServerAccessController axonServerAccessController); @Override ServerCall.Listener<T> interceptCall(ServerCall<T, R> serverCall, Metadata metadata, ServerCallHandler<T, R> serverCallHandler);  }### Answer:
@Test public void noToken() throws Exception { when(call.getMethodDescriptor()).thenReturn(path1); testSubject.interceptCall(call, metadata, handler); verify(call).close(status.capture(), trailers.capture()); assertEquals(PERMISSION_DENIED, status.getValue().getCode()); assertEquals("AXONIQ-1000", trailers.getValue().get(GrpcMetadataKeys.ERROR_CODE_KEY)); verify(handler, times(0)).startCall(any(), any()); }
@Test public void invalidToken() throws Exception { metadata.put(GrpcMetadataKeys.TOKEN_KEY, "1234"); when(call.getMethodDescriptor()).thenReturn(path1); testSubject.interceptCall(call, metadata, handler); verify(call).close(status.capture(), trailers.capture()); assertEquals(PERMISSION_DENIED, status.getValue().getCode()); assertEquals("AXONIQ-1001", trailers.getValue().get(GrpcMetadataKeys.ERROR_CODE_KEY)); verify(handler, times(0)).startCall(any(), any()); }
@Test public void validToken() throws Exception { metadata.put(GrpcMetadataKeys.TOKEN_KEY, "1234"); when(call.getMethodDescriptor()).thenReturn(path2); testSubject.interceptCall(call, metadata, handler); verify(handler, times(1)).startCall(any(), any()); }