Skip to content

Commit

Permalink
Expand test coverage of TestPlanSpecification
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Dec 4, 2015
1 parent 0dfc9d3 commit 82597c0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
Expand Up @@ -136,7 +136,11 @@ public TestPlanSpecification(List<TestPlanSpecificationElement> elements) {


@Override @Override
public Iterator<TestPlanSpecificationElement> iterator() { public Iterator<TestPlanSpecificationElement> iterator() {
return unmodifiableList(this.elements).iterator(); return getElements().iterator();
}

List<TestPlanSpecificationElement> getElements() {
return unmodifiableList(this.elements);
} }


public void accept(TestPlanSpecificationElementVisitor visitor) { public void accept(TestPlanSpecificationElementVisitor visitor) {
Expand Down
Expand Up @@ -10,8 +10,15 @@


package org.junit.gen5.engine; package org.junit.gen5.engine;


import static java.util.stream.Collectors.toList;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.gen5.engine.TestPlanSpecification.build;
import static org.junit.gen5.engine.TestPlanSpecification.forName;
import static org.junit.gen5.engine.TestPlanSpecification.forUniqueId;

import java.util.Arrays;
import java.util.List;


import org.junit.Test; import org.junit.Test;


Expand All @@ -23,38 +30,54 @@
public class TestPlanSpecificationTests { public class TestPlanSpecificationTests {


@Test @Test
public void testPlanBuilderDemo() { public void forUniqueIdForMethod() {
TestPlanSpecification specification = TestPlanSpecification.build( TestPlanSpecificationElement element = forUniqueId("junit5:org.example.UserTests#fullname()");
TestPlanSpecification.forUniqueId("junit5:org.example.UserTests#fullname()")); assertEquals(UniqueIdSpecification.class, element.getClass());
}


assertNotNull(specification); @Test
public void forNameWithClass() {
TestPlanSpecificationElement element = forName(MyTestClass.class.getName());
assertEquals(ClassSpecification.class, element.getClass());
} }


@Test @Test
public void testForNameWithClass() { public void forNameWithMethod() throws Exception {
TestPlanSpecificationElement specification = TestPlanSpecification.forName(MyTestClass.class.getName()); TestPlanSpecificationElement element = forName(fullyQualifiedMethodName());
assertEquals(ClassSpecification.class, specification.getClass()); assertEquals(MethodSpecification.class, element.getClass());
} }


@Test @Test
public void testForNameWithMethod() throws NoSuchMethodException { public void forNameWithPackage() {
String methodName = MyTestClass.class.getName() + "#" + MyTestClass.class.getDeclaredMethod("myTest").getName(); TestPlanSpecificationElement element = forName("org.junit.gen5");
TestPlanSpecificationElement specification = TestPlanSpecification.forName(methodName); assertEquals(PackageSpecification.class, element.getClass());
assertEquals(MethodSpecification.class, specification.getClass());
} }


@Test @Test
public void testForNameWithPackage() throws NoSuchMethodException { public void buildSpecification() throws Exception {
String packageName = "org.junit.gen5"; // @formatter:off
TestPlanSpecificationElement specification = TestPlanSpecification.forName(packageName); TestPlanSpecification spec = build(
assertEquals(PackageSpecification.class, specification.getClass()); forUniqueId("junit5:org.example.UserTests#fullname()"),
forName(MyTestClass.class.getName()),
forName("org.junit.gen5"),
forName(fullyQualifiedMethodName())
);
// @formatter:on

assertNotNull(spec);
List<Class<? extends TestPlanSpecificationElement>> expected = Arrays.asList(UniqueIdSpecification.class,
ClassSpecification.class, PackageSpecification.class, MethodSpecification.class);
assertEquals(expected, spec.getElements().stream().map(Object::getClass).collect(toList()));
} }


class MyTestClass { private String fullyQualifiedMethodName() throws Exception {
return MyTestClass.class.getName() + "#" + MyTestClass.class.getDeclaredMethod("myTest").getName();
}


@Test static class MyTestClass {
void myTest() {


void myTest() {
} }
} }

} }

0 comments on commit 82597c0

Please sign in to comment.