|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
6 | 6 | * You may obtain a copy of the License at
|
7 | 7 | *
|
8 |
| - * https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 | *
|
10 | 10 | * Unless required by applicable law or agreed to in writing, software
|
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| -package org.springframework.security.config.annotation |
| 16 | +package org.springframework.security.config.annotation; |
| 17 | + |
17 | 18 |
|
18 | 19 | import java.util.ArrayList;
|
19 | 20 | import java.util.List;
|
20 | 21 |
|
21 |
| -import spock.lang.Specification |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; |
| 25 | +import static org.mockito.Mockito.mock; |
22 | 26 |
|
23 | 27 | /**
|
24 | 28 | * @author Rob Winch
|
| 29 | + * @author Josh Cummings |
25 | 30 | *
|
26 | 31 | */
|
27 |
| -class SecurityConfigurerAdapterClosureTests extends Specification { |
28 |
| - ConcereteSecurityConfigurerAdapter conf = new ConcereteSecurityConfigurerAdapter() |
29 |
| - |
30 |
| - def "addPostProcessor closure"() { |
31 |
| - setup: |
32 |
| - SecurityBuilder<Object> builder = Mock() |
33 |
| - conf.addObjectPostProcessor({ List l -> |
34 |
| - l.add("a") |
35 |
| - l |
36 |
| - } as ObjectPostProcessor<List>) |
37 |
| - when: |
38 |
| - conf.init(builder) |
39 |
| - conf.configure(builder) |
40 |
| - then: |
41 |
| - conf.list.contains("a") |
| 32 | +public class SecurityConfigurerAdapterClosureTests { |
| 33 | + ConcereteSecurityConfigurerAdapter conf = new ConcereteSecurityConfigurerAdapter(); |
| 34 | + |
| 35 | + @Test |
| 36 | + public void addPostProcessorClosureWhenPostProcessThenGetsApplied() throws Exception { |
| 37 | + SecurityBuilder<Object> builder = mock(SecurityBuilder.class); |
| 38 | + this.conf.addObjectPostProcessor(new ObjectPostProcessor<List<String>>() { |
| 39 | + @Override |
| 40 | + public <O extends List<String>> O postProcess(O l) { |
| 41 | + l.add("a"); |
| 42 | + return l; |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + this.conf.init(builder); |
| 47 | + this.conf.configure(builder); |
| 48 | + |
| 49 | + assertThat(this.conf.list).contains("a"); |
42 | 50 | }
|
43 | 51 |
|
44 |
| - class ConcereteSecurityConfigurerAdapter extends |
| 52 | + static class ConcereteSecurityConfigurerAdapter extends |
45 | 53 | SecurityConfigurerAdapter<Object, SecurityBuilder<Object>> {
|
46 | 54 | private List<Object> list = new ArrayList<Object>();
|
47 | 55 |
|
48 | 56 | @Override
|
49 | 57 | public void configure(SecurityBuilder<Object> builder) throws Exception {
|
50 |
| - list = postProcess(list); |
| 58 | + this.list = postProcess(this.list); |
51 | 59 | }
|
52 | 60 |
|
53 | 61 | public ConcereteSecurityConfigurerAdapter list(List<Object> l) {
|
|
0 commit comments