|
| 1 | +/* |
| 2 | + * Copyright 2002-2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.security.web.authentication.switchuser; |
| 17 | + |
| 18 | +import org.junit.Test; |
| 19 | + |
| 20 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 21 | +import org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority; |
| 22 | + |
| 23 | +/** |
| 24 | + * |
| 25 | + * @author Clement Ng |
| 26 | + * |
| 27 | + */ |
| 28 | +public class SwitchUserGrantedAuthorityTests { |
| 29 | + |
| 30 | + /** |
| 31 | + * @throws Exception |
| 32 | + */ |
| 33 | + @Test |
| 34 | + public void authorityWithNullRoleFailsAssertion() throws Exception { |
| 35 | + assertThatThrownBy(() -> new SwitchUserGrantedAuthority(null, null)) |
| 36 | + .isInstanceOf(IllegalArgumentException.class) |
| 37 | + .hasMessage("role cannot be null"); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @throws Exception |
| 42 | + */ |
| 43 | + @Test |
| 44 | + public void authorityWithNullSourceFailsAssertion() throws Exception { |
| 45 | + assertThatThrownBy(() -> new SwitchUserGrantedAuthority("role", null)) |
| 46 | + .isInstanceOf(IllegalArgumentException.class) |
| 47 | + .hasMessage("source cannot be null"); |
| 48 | + } |
| 49 | +} |
0 commit comments