mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-07 19:22:14 +00:00
Polish ProviderManagerTests
- Renamed test to follow naming convention - Simplified mock with Mockito - Added note regarding related ticket Issue gh-8689
This commit is contained in:
parent
5302fb776c
commit
c177b391d4
@ -16,19 +16,27 @@
|
|||||||
|
|
||||||
package org.springframework.security.authentication;
|
package org.springframework.security.authentication;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.context.MessageSource;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.AuthenticationException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.fail;
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoInteractions;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link ProviderManager}.
|
* Tests {@link ProviderManager}.
|
||||||
@ -107,22 +115,12 @@ public class ProviderManagerTests {
|
|||||||
new ProviderManager(Arrays.asList(mock(AuthenticationProvider.class), null));
|
new ProviderManager(Arrays.asList(mock(AuthenticationProvider.class), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-8689
|
||||||
@Test
|
@Test
|
||||||
public void testUsingNullNotPermittedList() {
|
public void constructorWhenUsingListOfThenNoException() {
|
||||||
// imitated Java9 List.of(e) object, which disallows null elements and
|
List<AuthenticationProvider> providers = spy(ArrayList.class);
|
||||||
// throws NPE when contains(null) called
|
// List.of(null) in JDK 9 throws a NullPointerException
|
||||||
List<AuthenticationProvider> providers = new ArrayList<AuthenticationProvider>() {
|
when(providers.contains(eq(null))).thenThrow(NullPointerException.class);
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(Object o) {
|
|
||||||
if (o == null) {
|
|
||||||
throw new NullPointerException();
|
|
||||||
}
|
|
||||||
return super.contains(o);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
providers.add(mock(AuthenticationProvider.class));
|
providers.add(mock(AuthenticationProvider.class));
|
||||||
new ProviderManager(providers);
|
new ProviderManager(providers);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user