Skip to content

Commit 758af54

Browse files
committed
ObjectPostProcessor Tests groovy->java
Issue gh-4939
1 parent a08be5b commit 758af54

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,16 +15,17 @@
1515
*/
1616
package org.springframework.security.config.annotation;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
2018
import java.util.ArrayList;
2119
import java.util.LinkedList;
2220
import java.util.List;
2321

2422
import org.junit.Test;
2523

24+
import static org.assertj.core.api.Assertions.assertThat;
25+
2626
/**
2727
* @author Rob Winch
28+
* @author Josh Cummings
2829
*
2930
*/
3031
public class ObjectPostProcessorTests {
@@ -34,17 +35,19 @@ public void convertTypes() {
3435
assertThat((Object) PerformConversion.perform(new ArrayList<>()))
3536
.isInstanceOf(LinkedList.class);
3637
}
37-
}
3838

39-
class ListToLinkedListObjectPostProcessor implements ObjectPostProcessor<List<?>> {
39+
static class ListToLinkedListObjectPostProcessor implements ObjectPostProcessor<List<?>> {
4040

41-
public <O extends List<?>> O postProcess(O l) {
42-
return (O) new LinkedList(l);
41+
public <O extends List<?>> O postProcess(O l) {
42+
return (O) new LinkedList(l);
43+
}
4344
}
44-
}
4545

46-
class PerformConversion {
47-
public static List<?> perform(ArrayList<?> l) {
48-
return new ListToLinkedListObjectPostProcessor().postProcess(l);
46+
static class PerformConversion {
47+
public static List<?> perform(ArrayList<?> l) {
48+
return new ListToLinkedListObjectPostProcessor().postProcess(l);
49+
}
4950
}
5051
}
52+
53+
Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,61 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.security.config.annotation
16+
package org.springframework.security.config.annotation;
17+
1718

1819
import java.util.ArrayList;
1920
import java.util.List;
2021

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;
2226

2327
/**
2428
* @author Rob Winch
29+
* @author Josh Cummings
2530
*
2631
*/
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");
4250
}
4351

44-
class ConcereteSecurityConfigurerAdapter extends
52+
static class ConcereteSecurityConfigurerAdapter extends
4553
SecurityConfigurerAdapter<Object, SecurityBuilder<Object>> {
4654
private List<Object> list = new ArrayList<Object>();
4755

4856
@Override
4957
public void configure(SecurityBuilder<Object> builder) throws Exception {
50-
list = postProcess(list);
58+
this.list = postProcess(this.list);
5159
}
5260

5361
public ConcereteSecurityConfigurerAdapter list(List<Object> l) {

0 commit comments

Comments
 (0)