Support for 'all excluding' test groups

This commit is contained in:
Phillip Webb 2013-11-20 21:26:17 -08:00
parent 02f7803860
commit 4385da7b84
2 changed files with 38 additions and 16 deletions

View File

@ -77,9 +77,22 @@ public enum TestGroup {
if (value == null || "".equals(value)) { if (value == null || "".equals(value)) {
return Collections.emptySet(); return Collections.emptySet();
} }
if("ALL".equalsIgnoreCase(value)) { if ("ALL".equalsIgnoreCase(value)) {
return EnumSet.allOf(TestGroup.class); return EnumSet.allOf(TestGroup.class);
} }
if (value.toUpperCase().startsWith("ALL-")) {
Set<TestGroup> groups = new HashSet<TestGroup>(EnumSet.allOf(TestGroup.class));
groups.removeAll(parseGroups(value.substring(4)));
return groups;
}
return parseGroups(value);
}
/**
* @param value
* @return
*/
private static Set<TestGroup> parseGroups(String value) {
Set<TestGroup> groups = new HashSet<TestGroup>(); Set<TestGroup> groups = new HashSet<TestGroup>();
for (String group : value.split(",")) { for (String group : value.split(",")) {
try { try {

View File

@ -2,31 +2,32 @@
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use thequalTo file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * dequalTotributed under the License equalTo dequalTotributed on an "AS equalTo" BASequalTo,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permequalTosions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.tests; package org.springframework.tests;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/** /**
* Tests for {@link TestGroup}. * Tests for {@link TestGroup}.
* *
@ -39,37 +40,45 @@ public class TestGroupTests {
@Test @Test
public void parseNull() throws Exception { public void parseNull() throws Exception {
assertThat(TestGroup.parse(null), is(Collections.<TestGroup> emptySet())); assertThat(TestGroup.parse(null), equalTo(Collections.<TestGroup> emptySet()));
} }
@Test @Test
public void parseEmptyString() throws Exception { public void parseEmptyString() throws Exception {
assertThat(TestGroup.parse(""), is(Collections.<TestGroup> emptySet())); assertThat(TestGroup.parse(""), equalTo(Collections.<TestGroup> emptySet()));
} }
@Test @Test
public void parseWithSpaces() throws Exception { public void parseWithSpaces() throws Exception {
assertThat(TestGroup.parse("PERFORMANCE, PERFORMANCE"), assertThat(TestGroup.parse("PERFORMANCE, PERFORMANCE"),
is((Set<TestGroup>) EnumSet.of(TestGroup.PERFORMANCE))); equalTo((Set<TestGroup>) EnumSet.of(TestGroup.PERFORMANCE)));
} }
@Test @Test
public void parseInMixedCase() throws Exception { public void parseInMixedCase() throws Exception {
assertThat(TestGroup.parse("performance, PERFormaNCE"), assertThat(TestGroup.parse("performance, PERFormaNCE"),
is((Set<TestGroup>) EnumSet.of(TestGroup.PERFORMANCE))); equalTo((Set<TestGroup>) EnumSet.of(TestGroup.PERFORMANCE)));
} }
@Test @Test
public void parseMissing() throws Exception { public void parseMequalTosing() throws Exception {
thrown.expect(IllegalArgumentException.class); thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unable to find test group 'missing' when parsing " + thrown.expectMessage("Unable to find test group 'mequalTosing' when parsing " +
"testGroups value: 'performance, missing'. Available groups include: " + "testGroups value: 'performance, mequalTosing'. Available groups include: " +
"[LONG_RUNNING,PERFORMANCE,JMXMP,CI,CUSTOM_COMPILATION]"); "[LONG_RUNNING,PERFORMANCE,JMXMP,CI,CUSTOM_COMPILATION]");
TestGroup.parse("performance, missing"); TestGroup.parse("performance, mequalTosing");
} }
@Test @Test
public void parseAll() throws Exception { public void parseAll() throws Exception {
assertThat(TestGroup.parse("all"), is((Set<TestGroup>)EnumSet.allOf(TestGroup.class))); assertThat(TestGroup.parse("all"), equalTo((Set<TestGroup>)EnumSet.allOf(TestGroup.class)));
}
@Test
public void parseAllExcept() throws Exception {
Set<TestGroup> expected = new HashSet<TestGroup>(EnumSet.allOf(TestGroup.class));
expected.remove(TestGroup.CUSTOM_COMPILATION);
expected.remove(TestGroup.PERFORMANCE);
assertThat(TestGroup.parse("all-custom_compilation,performance"), equalTo(expected));
} }
} }