### Question:
ReactiveSecurityContext { static public Mono<XsuaaToken> getToken() { return ReactiveSecurityContextHolder.getContext() .switchIfEmpty(Mono.error(new AccessDeniedException("Access forbidden: not authenticated"))) .map(SecurityContext::getAuthentication) .map(Authentication::getCredentials) .map(credentials -> new XsuaaToken((Jwt) credentials)) .doOnSuccess(token -> logger.info("Got Jwt token: {}", token)) .doOnError(throwable -> logger.error("ERROR to getToken", throwable)); } private  ReactiveSecurityContext(); static Mono<XsuaaToken> getToken();  }### Answer:
@Test public void unauthenticated() { SecurityContext expectedContext = new SecurityContextImpl(); ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)); Mono<XsuaaToken> tokenMono = ReactiveSecurityContext.getToken(); StepVerifier.create(tokenMono) .expectError(AccessDeniedException.class) .verify(); }
@Test @Ignore public void authenticated() { XsuaaToken jwt = new XsuaaToken(new JwtGenerator().setUserName("user").getToken()); SecurityContext expectedContext = new SecurityContextImpl( new TestingAuthenticationToken("user", jwt, "ROLE_USER")); ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)); Mono<XsuaaToken> tokenMono = ReactiveSecurityContext.getToken(); StepVerifier.create(tokenMono) .expectNext(jwt) .verifyComplete(); }