Skip to content

Commit 2d69150

Browse files
committed
Add tests
Issue spring-projectsgh-60
1 parent e7ab8b1 commit 2d69150

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2020-2024 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.oauth2.server.authorization.authentication;
17+
18+
import java.util.List;
19+
import java.util.Map;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.security.authentication.TestingAuthenticationToken;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
27+
28+
/**
29+
* Tests for {@link OAuth2TokenExchangeCompositeAuthenticationToken}.
30+
*
31+
* @author Steve Riesenberg
32+
*/
33+
public class OAuth2TokenExchangeCompositeAuthenticationTokenTests {
34+
35+
@Test
36+
public void constructorWhenSubjectNullThenThrowIllegalArgumentException() {
37+
// @formatter:off
38+
assertThatIllegalArgumentException()
39+
.isThrownBy(() -> new OAuth2TokenExchangeCompositeAuthenticationToken(null, null))
40+
.withMessage("subject cannot be null");
41+
// @formatter:on
42+
}
43+
44+
@Test
45+
public void constructorWhenActorsNullThenThrowIllegalArgumentException() {
46+
TestingAuthenticationToken subject = new TestingAuthenticationToken("subject", null);
47+
// @formatter:off
48+
assertThatIllegalArgumentException()
49+
.isThrownBy(() -> new OAuth2TokenExchangeCompositeAuthenticationToken(subject, null))
50+
.withMessage("actors cannot be null");
51+
// @formatter:on
52+
}
53+
54+
@Test
55+
public void constructorWhenRequiredParametersProvidedThenCreated() {
56+
TestingAuthenticationToken subject = new TestingAuthenticationToken("subject", null);
57+
OAuth2TokenExchangeActor actor1 = new OAuth2TokenExchangeActor(Map.of("claim1", "value1"));
58+
OAuth2TokenExchangeActor actor2 = new OAuth2TokenExchangeActor(Map.of("claim2", "value2"));
59+
List<OAuth2TokenExchangeActor> actors = List.of(actor1, actor2);
60+
OAuth2TokenExchangeCompositeAuthenticationToken authentication =
61+
new OAuth2TokenExchangeCompositeAuthenticationToken(subject, actors);
62+
assertThat(authentication.getSubject()).isEqualTo(subject);
63+
assertThat(authentication.getActors()).isEqualTo(actors);
64+
}
65+
66+
}

0 commit comments

Comments
 (0)