SEC-2151: Fix tests

This commit is contained in:
Rob Winch 2013-09-27 11:52:32 -05:00
parent a09756745f
commit e5f034bdef
2 changed files with 48 additions and 28 deletions

View File

@ -1,25 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.springframework.core;
/**
*
* @author Rob Winch
*
*/
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
}

View File

@ -21,11 +21,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.SpringVersion;
import org.springframework.security.access.method.P;
import org.springframework.test.util.ReflectionTestUtils;
@ -45,6 +46,8 @@ public class DefaultSecurityParameterNameDiscovererTests {
@Test
public void constructorDefault() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("3."));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(discoverer, "parameterNameDiscoverers");
@ -57,11 +60,13 @@ public class DefaultSecurityParameterNameDiscovererTests {
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(1)).isInstanceOf(
DefaultParameterNameDiscoverer.class);
LocalVariableTableParameterNameDiscoverer.class);
}
@Test
public void constructorDiscoverers() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("3."));
discoverer = new DefaultSecurityParameterNameDiscoverer(Arrays.asList(new LocalVariableTableParameterNameDiscoverer()));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
@ -78,6 +83,46 @@ public class DefaultSecurityParameterNameDiscovererTests {
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(2)).isInstanceOf(
DefaultParameterNameDiscoverer.class);
LocalVariableTableParameterNameDiscoverer.class);
}
@Test
public void constructorDefaultSpring4() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("4."));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(discoverer, "parameterNameDiscoverers");
assertThat(discoverers.size()).isEqualTo(2);
ParameterNameDiscoverer annotationDisc = discoverers.get(0);
assertThat(annotationDisc).isInstanceOf(
AnnotationParameterNameDiscoverer.class);
Set<String> annotationsToUse = (Set<String>)ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(1).getClass().getName()).isEqualTo("org.springframework.core.DefaultParameterNameDiscoverer");
}
@Test
public void constructorDiscoverersSpring4() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("4."));
discoverer = new DefaultSecurityParameterNameDiscoverer(Arrays.asList(new LocalVariableTableParameterNameDiscoverer()));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(discoverer, "parameterNameDiscoverers");
assertThat(discoverers.size()).isEqualTo(3);
assertThat(discoverers.get(0)).isInstanceOf(
LocalVariableTableParameterNameDiscoverer.class);
ParameterNameDiscoverer annotationDisc = discoverers.get(1);
assertThat(annotationDisc).isInstanceOf(
AnnotationParameterNameDiscoverer.class);
Set<String> annotationsToUse = (Set<String>)ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(1).getClass().getName()).isEqualTo("org.springframework.core.DefaultParameterNameDiscoverer");
}
}