diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/account/event/PasswordChangeEventPublisherTests.java b/server/src/test/java/org/cloudfoundry/identity/uaa/account/event/PasswordChangeEventPublisherTests.java index 701a95a8ef7..1260b7aa127 100644 --- a/server/src/test/java/org/cloudfoundry/identity/uaa/account/event/PasswordChangeEventPublisherTests.java +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/account/event/PasswordChangeEventPublisherTests.java @@ -1,16 +1,3 @@ -/******************************************************************************* - * Cloud Foundry - * Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved. - * - * This product is licensed to you under the Apache License, Version 2.0 (the "License"). - * You may not use this product except in compliance with the License. - * - * This product includes a number of subcomponents with - * separate copyright notices and license terms. Your use of these - * subcomponents is subject to the terms and conditions of the - * subcomponent's license, as noted in the LICENSE file. - *******************************************************************************/ - package org.cloudfoundry.identity.uaa.account.event; import org.cloudfoundry.identity.uaa.account.UaaPasswordTestFactory; @@ -30,9 +17,10 @@ import org.springframework.security.oauth2.provider.AuthorizationRequest; import org.springframework.security.oauth2.provider.OAuth2Authentication; -import java.util.Arrays; +import java.util.Collections; import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.when; public class PasswordChangeEventPublisherTests { @@ -47,9 +35,9 @@ public class PasswordChangeEventPublisherTests { public void init() { subject.setApplicationEventPublisher(publisher); authentication = new OAuth2Authentication( - new AuthorizationRequest( - "client", - Arrays.asList("read")).createOAuth2Request(), + new AuthorizationRequest( + "client", + Collections.singletonList("read")).createOAuth2Request(), UaaPasswordTestFactory.getAuthentication("ID", "joe", "joe@test.org") ); SecurityContextHolder.getContext().setAuthentication(authentication); @@ -62,37 +50,37 @@ public void destroy() { @Test public void testPasswordChange() { - Mockito.when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenReturn( - ScimUserTestFactory.getScimUser("joe", "joe@test.org", "Joe", "Schmo")); + when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenReturn( + ScimUserTestFactory.getScimUser("joe", "joe@test.org", "Joe", "Schmo")); subject.passwordChange("foo"); Mockito.verify(publisher).publishEvent(ArgumentMatchers.isA(PasswordChangeEvent.class)); } @Test public void testPasswordChangeNoEmail() { - Mockito.when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenReturn( - ScimUserTestFactory.getScimUser("joe", null, "Joe", "Schmo")); + when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenReturn( + ScimUserTestFactory.getScimUser("joe", null, "Joe", "Schmo")); subject.passwordChange("foo"); Mockito.verify(publisher).publishEvent(ArgumentMatchers.isA(PasswordChangeEvent.class)); } @Test public void testPasswordFailure() { - Mockito.when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenReturn( - ScimUserTestFactory.getScimUser("joe", "joe@test.org", "Joe", "Schmo")); + when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenReturn( + ScimUserTestFactory.getScimUser("joe", "joe@test.org", "Joe", "Schmo")); subject.passwordFailure("foo", new RuntimeException("planned")); Mockito.verify(publisher).publishEvent(ArgumentMatchers.isA(PasswordChangeFailureEvent.class)); } @Test public void testPasswordFailureNoUser() { - Mockito.when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenThrow(new ScimResourceNotFoundException("Not found")); + when(scimUserProvisioning.retrieve("foo", IdentityZoneHolder.get().getId())).thenThrow(new ScimResourceNotFoundException("Not found")); subject.passwordFailure("foo", new RuntimeException("planned")); Mockito.verify(publisher).publishEvent(ArgumentMatchers.any(PasswordChangeFailureEvent.class)); } @Test - public void not_authenticated_returns_system_auth() throws Exception { + public void notAuthenticatedReturnsSystemAuth() { assertSame(authentication, subject.getPrincipal()); SecurityContextHolder.clearContext(); assertSame(SystemAuthentication.SYSTEM_AUTHENTICATION, subject.getPrincipal());