Skip to content

Commit

Permalink
Introduce precondition checks in AbstractTestDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Nov 7, 2015
1 parent 87c0ed5 commit 545bf79
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
1 change: 1 addition & 0 deletions junit-engine-api/build.gradle
@@ -1,2 +1,3 @@
dependencies { dependencies {
compile(project(':junit-commons'))
} }
Expand Up @@ -10,54 +10,68 @@


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


import java.util.HashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;


import org.junit.gen5.commons.util.Preconditions;

/**
* @author Sam Brannen
* @since 5.0
*/
public abstract class AbstractTestDescriptor implements TestDescriptor { public abstract class AbstractTestDescriptor implements TestDescriptor {


private final String uniqueId; private final String uniqueId;

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


protected AbstractTestDescriptor(String uniqueId) { protected AbstractTestDescriptor(String uniqueId) {
Preconditions.notBlank(uniqueId, "uniqueId must not be null or empty");
this.uniqueId = uniqueId; this.uniqueId = uniqueId;
} }


@Override @Override
public boolean equals(Object other) { public final String getUniqueId() {
if (other == null) return this.uniqueId;
return false;
if (this.getClass() != other.getClass())
return false;
TestDescriptor otherDescriptor = (TestDescriptor) other;
return this.getUniqueId().equals(otherDescriptor.getUniqueId());
} }


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


@Override protected final void setParent(TestDescriptor parent) {
public String getUniqueId() { Preconditions.notNull(parent, "parent must not be null");
return uniqueId; this.parent = parent;
} }


@Override public final void addChild(AbstractTestDescriptor child) {
public TestDescriptor getParent() { Preconditions.notNull(child, "child must not be null");
return parent; child.setParent(this);
this.children.add(child);
} }


protected void setParent(TestDescriptor parent) { public final Set<AbstractTestDescriptor> getChildren() {
this.parent = parent; return this.children;
} }


public void addChild(AbstractTestDescriptor child) { @Override
child.setParent(this); public final boolean equals(Object other) {
children.add(child); if (other == null) {
return false;
}
if (this.getClass() != other.getClass()) {
return false;
}
TestDescriptor otherDescriptor = (TestDescriptor) other;
return this.getUniqueId().equals(otherDescriptor.getUniqueId());
} }


public Set<TestDescriptor> getChildren() { @Override
return children; public final int hashCode() {
return this.uniqueId.hashCode();
} }

} }

0 comments on commit 545bf79

Please sign in to comment.