@Test public void getWithoutAuthenticationInContext() { Optional<CoffeeNetUserDetails> coffeeNetUserDetails = sut.get(); MatcherAssert.assertThat(coffeeNetUserDetails.isPresent(), is(false)); }
@Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); } }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }  }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }  @Override Optional<CoffeeNetUserDetails> get(); }
IntegrationCoffeeNetCurrentUserService implements CoffeeNetCurrentUserService { @Override public Optional<CoffeeNetUserDetails> get() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return Optional.empty(); } Object principal = authentication.getPrincipal(); if (!(principal instanceof CoffeeNetUserDetails)) { return Optional.empty(); } return Optional.of((CoffeeNetUserDetails) principal); }  @Override Optional<CoffeeNetUserDetails> get();  }