Polish Tests

Issue gh-11992
This commit is contained in:
Josh Cummings 2022-11-16 13:59:29 -07:00
parent 4e88623873
commit 88e64bac0c
2 changed files with 10 additions and 7 deletions

View File

@ -33,11 +33,11 @@ import org.springframework.security.core.Authentication;
*/
public final class ObservationSecurityContextChangedListener implements SecurityContextChangedListener {
private static final String SECURITY_CONTEXT_CREATED = "security.context.created";
static final String SECURITY_CONTEXT_CREATED = "security.context.created";
private static final String SECURITY_CONTEXT_CHANGED = "security.context.changed";
static final String SECURITY_CONTEXT_CHANGED = "security.context.changed";
private static final String SECURITY_CONTEXT_CLEARED = "security.context.cleared";
static final String SECURITY_CONTEXT_CLEARED = "security.context.cleared";
private final ObservationRegistry registry;
@ -60,7 +60,7 @@ public final class ObservationSecurityContextChangedListener implements Security
return;
}
if (event.isCleared()) {
observation.event(Observation.Event.of("security.context.cleared"));
observation.event(Observation.Event.of(SECURITY_CONTEXT_CLEARED));
return;
}
Authentication oldAuthentication = getAuthentication(event.getOldContext());

View File

@ -66,7 +66,8 @@ public class ObservationSecurityContextChangedListenerTests {
.securityContextChanged(new SecurityContextChangedEvent(one, SecurityContextChangedEvent.NO_CONTEXT));
ArgumentCaptor<Observation.Event> event = ArgumentCaptor.forClass(Observation.Event.class);
verify(observation).event(event.capture());
assertThat(event.getValue().getName()).isEqualTo("security.context.cleared");
assertThat(event.getValue().getName())
.isEqualTo(ObservationSecurityContextChangedListener.SECURITY_CONTEXT_CLEARED);
verifyNoInteractions(one);
}
@ -85,7 +86,8 @@ public class ObservationSecurityContextChangedListenerTests {
this.tested.securityContextChanged(new SecurityContextChangedEvent(this.one, this.two));
ArgumentCaptor<Observation.Event> event = ArgumentCaptor.forClass(Observation.Event.class);
verify(observation).event(event.capture());
assertThat(event.getValue().getName()).isEqualTo("security.context.changed");
assertThat(event.getValue().getName())
.isEqualTo(ObservationSecurityContextChangedListener.SECURITY_CONTEXT_CHANGED);
}
@Test
@ -95,7 +97,8 @@ public class ObservationSecurityContextChangedListenerTests {
this.tested.securityContextChanged(new SecurityContextChangedEvent(null, this.one));
ArgumentCaptor<Observation.Event> event = ArgumentCaptor.forClass(Observation.Event.class);
verify(observation).event(event.capture());
assertThat(event.getValue().getName()).isEqualTo("security.context.created");
assertThat(event.getValue().getName())
.isEqualTo(ObservationSecurityContextChangedListener.SECURITY_CONTEXT_CREATED);
}
}