Enable reuse of DefaultActiveProfilesResolver

In order to allow DefaultActiveProfilesResolver to be reused (e.g., via
extension or delegation), the check which asserts that the 'resolver'
attribute of @ActiveProfiles is not set to a customer resolver class
has been removed.

Issue: SPR-12611
This commit is contained in:
Sam Brannen
2015-01-10 20:36:48 +01:00
parent cf7a7932f3
commit 276712dcd1
2 changed files with 41 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -20,14 +20,17 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ActiveProfilesResolver;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*;
import static org.springframework.test.context.support.ActiveProfilesUtils.*;
@@ -211,7 +214,6 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT
/**
* This test verifies that the actual test class, not the composed annotation,
* is passed to the resolver.
*
* @since 4.0.3
*/
@Test
@@ -220,6 +222,24 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT
assertResolvedProfiles(testClass, testClass.getSimpleName());
}
/**
* This test verifies that {@link DefaultActiveProfilesResolver} can be declared explicitly.
* @since 4.1.5
*/
@Test
public void resolveActiveProfilesWithDefaultActiveProfilesResolver() {
assertResolvedProfiles(DefaultActiveProfilesResolverTestCase.class, "default");
}
/**
* This test verifies that {@link DefaultActiveProfilesResolver} can be extended.
* @since 4.1.5
*/
@Test
public void resolveActiveProfilesWithExtendedDefaultActiveProfilesResolver() {
assertResolvedProfiles(ExtendedDefaultActiveProfilesResolverTestCase.class, "default", "foo");
}
// -------------------------------------------------------------------------
@@ -294,6 +314,14 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT
private static class TestClassVerifyingActiveProfilesResolverTestCase {
}
@ActiveProfiles(profiles = "default", resolver = DefaultActiveProfilesResolver.class)
private static class DefaultActiveProfilesResolverTestCase {
}
@ActiveProfiles(profiles = "default", resolver = ExtendedDefaultActiveProfilesResolver.class)
private static class ExtendedDefaultActiveProfilesResolverTestCase {
}
@ActiveProfiles(profiles = "conflict 1", value = "conflict 2")
private static class ConflictingProfilesAndValueTestCase {
}
@@ -343,4 +371,14 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT
}
}
private static class ExtendedDefaultActiveProfilesResolver extends DefaultActiveProfilesResolver {
@Override
public String[] resolve(Class<?> testClass) {
List<String> profiles = new ArrayList<String>(Arrays.asList(super.resolve(testClass)));
profiles.add("foo");
return StringUtils.toStringArray(profiles);
}
}
}