Skip to content

Commit

Permalink
added LoggingSuspender
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Wagner committed Feb 7, 2012
1 parent 1552998 commit 1c1727b
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions test_src/org/arabidopsis/interval/RbTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

class LoggingSuspender {
interface Action {
public void doit();
}

public static void performAction(final Logger theLogger, final Action theAction){
final Level previousLevel = theLogger.getLevel();
theLogger.setLevel(Level.OFF);
theAction.doit();
theLogger.setLevel(previousLevel);
}
}


public class RbTreeTest {
private RbTree tree;
Expand Down Expand Up @@ -42,8 +57,16 @@ public void testTreeWithRootColorDamageIsntValid() {
this.tree.insert(new RbNode(5));
final RbNode node = this.tree.get(5);
node.color = RbNode.RED;
this.tree.logger.warn("Following log entry expected to be: 'root color is wrong'");
assertFalse(this.tree.isValid());

LoggingSuspender.performAction(this.tree.logger, new LoggingSuspender.Action(){

@Override
public void doit() {
tree.logger.warn("haha");
assertFalse(RbTreeTest.this.tree.isValid());
}
});

}


Expand All @@ -64,8 +87,15 @@ public void testDamageCanBeDetected() {
}
assertTrue(this.tree.isValid());
intentionallyColorAllNodesBlack(this.tree.root);
this.tree.logger.warn("Following log entry expected to be: 'black height unbalanced'");
assertFalse(this.tree.isValid());

LoggingSuspender.performAction(this.tree.logger, new LoggingSuspender.Action(){

@Override
public void doit() {
assertFalse(RbTreeTest.this.tree.isValid());
}
});

}


Expand Down

0 comments on commit 1c1727b

Please sign in to comment.