Skip to content

Commit

Permalink
Merge branch 'optimize-filter-intersect' of https://github.com/kcoone…
Browse files Browse the repository at this point in the history
…y/junit into kcooney-optimize-filter-intersect
  • Loading branch information
dsaff committed Jun 14, 2011
2 parents 3d2826c + a4c5380 commit 2774e2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/org/junit/runner/manipulation/Filter.java
Expand Up @@ -30,7 +30,12 @@ public String describe() {
@Override
public void apply(Object child) throws NoTestsRemainException {
// do nothing
};
}

@Override
public Filter intersect(Filter second) {
return second;
}
};

/**
Expand Down Expand Up @@ -89,6 +94,9 @@ public void apply(Object child) throws NoTestsRemainException {
* by this Filter and {@code second}
*/
public Filter intersect(final Filter second) {
if (second == this || second == ALL) {
return this;
}
final Filter first= this;
return new Filter() {
@Override
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/junit/tests/manipulation/FilterTest.java
@@ -1,6 +1,7 @@
package org.junit.tests.manipulation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;
Expand Down Expand Up @@ -31,4 +32,18 @@ public void intersectionText() {
assertEquals("a and b", a.intersect(b).describe());
assertEquals("b and a", b.intersect(a).describe());
}

@Test
public void intersectSelf() {
NamedFilter a= new NamedFilter("a");
assertSame(a, a.intersect(a));
}

@Test
public void intersectAll() {
NamedFilter a= new NamedFilter("a");
assertSame(a, a.intersect(Filter.ALL));
assertSame(a, Filter.ALL.intersect(a));
assertSame(Filter.ALL, Filter.ALL.intersect(Filter.ALL));
}
}

0 comments on commit 2774e2d

Please sign in to comment.