Skip to content

Commit

Permalink
Polish test
Browse files Browse the repository at this point in the history
Issue: #40

------------------------------------------------------------------------
On behalf of the community, the JUnit Lambda Team thanks
Samuraism, Inc. (http://samuraism.com/) for supporting the
JUnit crowdfunding campaign!
------------------------------------------------------------------------
  • Loading branch information
marcphilipp committed Jan 2, 2016
1 parent 2309f89 commit 53a72fe
Showing 1 changed file with 27 additions and 13 deletions.
Expand Up @@ -11,12 +11,14 @@
package org.junit.gen5.engine.junit4; package org.junit.gen5.engine.junit4;


import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.gen5.api.Assertions.assertEquals; import static org.junit.gen5.api.Assertions.*;
import static org.junit.gen5.engine.TestPlanSpecification.*; import static org.junit.gen5.engine.TestPlanSpecification.*;


import java.util.Iterator;

import org.junit.Assert; import org.junit.Assert;
import org.junit.gen5.api.Test; import org.junit.gen5.api.Test;
import org.junit.gen5.engine.EngineAwareTestDescriptor; import org.junit.gen5.commons.util.Preconditions;
import org.junit.gen5.engine.TestDescriptor; import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestPlanSpecification; import org.junit.gen5.engine.TestPlanSpecification;


Expand All @@ -26,29 +28,41 @@ class JUnit4TestEngineClassSpecificationResolutionTests {


@Test @Test
void resolvesSimpleJUnit4TestClass() { void resolvesSimpleJUnit4TestClass() {
TestPlanSpecification specification = build(forClass(SimpleJUnit4TestCase.class)); Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;

TestPlanSpecification specification = build(forClass(testClass));
EngineAwareTestDescriptor engineDescriptor = engine.discoverTests(specification);


assertThat(engineDescriptor.getChildren()).hasSize(1); TestDescriptor engineDescriptor = engine.discoverTests(specification);


TestDescriptor runnerDescriptor = engineDescriptor.getChildren().iterator().next(); TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertEquals("junit4:" + SimpleJUnit4TestCase.class.getName(), runnerDescriptor.getUniqueId()); assertTrue(runnerDescriptor.isContainer());
assertThat(runnerDescriptor.getChildren()).hasSize(1); assertFalse(runnerDescriptor.isTest());
assertEquals(testClass.getName(), runnerDescriptor.getDisplayName());
assertEquals("junit4:" + testClass.getName(), runnerDescriptor.getUniqueId());


TestDescriptor childDescriptor = runnerDescriptor.getChildren().iterator().next(); TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
assertEquals( assertTrue(childDescriptor.isTest());
"junit4:" + SimpleJUnit4TestCase.class.getName() + "/test(" + SimpleJUnit4TestCase.class.getName() + ")", assertFalse(childDescriptor.isContainer());
// TODO #40 Get rid of "(className)" suffix?
assertEquals("test(" + testClass.getName() + ")", childDescriptor.getDisplayName());
assertEquals("junit4:" + testClass.getName() + "/test(" + testClass.getName() + ")",
childDescriptor.getUniqueId()); childDescriptor.getUniqueId());
assertThat(childDescriptor.getChildren()).isEmpty(); assertThat(childDescriptor.getChildren()).isEmpty();
} }


public static class SimpleJUnit4TestCase { public static class PlainJUnit4TestCaseWithSingleTestWhichFails {


@org.junit.Test @org.junit.Test
public void test() { public void test() {
Assert.fail("this test should fail"); Assert.fail("this test should fail");
} }


} }

private static <T> T getOnlyElement(Iterable<T> iterable) {
Iterator<T> iterator = iterable.iterator();
Preconditions.condition(iterator.hasNext(), () -> "iterable must not be empty: " + iterable);
T result = iterator.next();
Preconditions.condition(!iterator.hasNext(), () -> "iterable must not contain more than one item: " + iterable);
return result;
}
} }

0 comments on commit 53a72fe

Please sign in to comment.