Skip to content

Commit

Permalink
TestDescriptor now has addChild and getChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Nov 8, 2015
1 parent 1105bef commit 2fe6c74
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
Expand Up @@ -26,7 +26,7 @@ public abstract class AbstractTestDescriptor implements TestDescriptor {

private TestDescriptor parent;

private final Set<AbstractTestDescriptor> children = new LinkedHashSet<>();
private final Set<TestDescriptor> children = new LinkedHashSet<>();

protected AbstractTestDescriptor(String uniqueId) {
Preconditions.notBlank(uniqueId, "uniqueId must not be null or empty");
Expand All @@ -39,7 +39,7 @@ public final String getUniqueId() {
}

@Override
public final TestDescriptor getParent() {
public TestDescriptor getParent() {
return this.parent;
}

Expand All @@ -48,13 +48,14 @@ protected final void setParent(TestDescriptor parent) {
this.parent = parent;
}

public final void addChild(AbstractTestDescriptor child) {
public final void addChild(TestDescriptor child) {
Preconditions.notNull(child, "child must not be null");
child.setParent(this);
if (child instanceof AbstractTestDescriptor)
((AbstractTestDescriptor) child).setParent(this);
this.children.add(child);
}

public final Set<AbstractTestDescriptor> getChildren() {
public final Set<TestDescriptor> getChildren() {
return this.children;
}

Expand Down
Expand Up @@ -33,4 +33,8 @@ public interface TestDescriptor {
boolean isTest();

Set<TestTag> getTags();

void addChild(TestDescriptor descriptor);

Set<TestDescriptor> getChildren();
}
Expand Up @@ -12,19 +12,21 @@

import java.util.Collections;
import java.util.Set;

import lombok.Data;

import org.junit.gen5.engine.AbstractTestDescriptor;
import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestTag;
import org.junit.runner.Description;

@Data
class DescriptionTestDescriptor implements TestDescriptor {
class DescriptionTestDescriptor extends AbstractTestDescriptor {

private final TestDescriptor parent;
private final Description description;

DescriptionTestDescriptor(TestDescriptor parent, Description description) {
super("junit4:" + description.getDisplayName());
parent.addChild(this);
this.description = description;
}

@Override
public boolean isTest() {
return description.isTest();
Expand All @@ -35,19 +37,12 @@ public Set<TestTag> getTags() {
return Collections.emptySet();
}

@Override
public String getUniqueId() {
// TODO Use unique ID if set, too
return "junit4:" + description.getDisplayName();
}

@Override
public TestDescriptor getParent() {
return parent;
}

@Override
public String getDisplayName() {
return description.getDisplayName();
}

public Description getDescription() {
return description;
}
}
Expand Up @@ -10,14 +10,9 @@

package org.junit.gen5.engine.junit4;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.junit.gen5.engine.TestDescriptor;
import org.junit.runner.Runner;

@Data
@EqualsAndHashCode(callSuper = false)
class RunnerTestDescriptor extends DescriptionTestDescriptor {

private Runner runner;
Expand All @@ -27,4 +22,7 @@ public RunnerTestDescriptor(TestDescriptor parent, Runner runner) {
this.runner = runner;
}

public Runner getRunner() {
return runner;
}
}
Expand Up @@ -10,8 +10,6 @@

package com.example;

import static org.junit.gen5.junit4runner.JUnit5.*;

import org.junit.gen5.junit4runner.JUnit5;
import org.junit.gen5.junit4runner.JUnit5.Classes;
import org.junit.gen5.junit4runner.JUnit5.Packages;
Expand All @@ -23,8 +21,8 @@
@UniqueIds({ "junit5:com.example.SampleTestCase#assertAllTest()",
"junit5:com.example.SampleTestCase#assertAllFailingTest()" })
@Packages({ "com.example.subpackage" })
@OnlyIncludeTags({ "fast" })
@OnlyEngine("junit5")
//@OnlyIncludeTags({ "fast" })
//@OnlyEngine("junit5")
public class JUnit4SamplesSuite {

// When you have the following method, it overrides all annotations
Expand Down

0 comments on commit 2fe6c74

Please sign in to comment.