expectationcountertest.java
来自「不管是测试驱动开发或者是其它的开发模式」· Java 代码 · 共 93 行
JAVA
93 行
/* Copyright (c) 2000-2004 jMock.org
*/
package test.jmock.expectation;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jmock.expectation.AssertMo;
import org.jmock.expectation.ExpectationCounter;
public class ExpectationCounterTest extends TestCase
{
public void testExpectNothing() {
ExpectationCounter e = new ExpectationCounter("");
e.setExpectNothing();
assertTrue("Has expectation", e.hasExpectations());
e.verify();
}
public void testExpectNothingFailure() {
ExpectationCounter e = new ExpectationCounter("");
e.setExpectNothing();
assertTrue("Has expectation", e.hasExpectations());
try {
e.inc();
}
catch (AssertionFailedError ex) {
return;
}
fail("Should have failed immediately");
}
public void testFailImmediately() {
ExpectationCounter aCounter = new ExpectationCounter("a test counter");
aCounter.setExpected(1);
aCounter.inc();
try {
aCounter.inc();
}
catch (AssertionFailedError ex) {
return;
}
fail("Should have failed immediately");
}
public void testFailOnVerify() {
ExpectationCounter aCounter = new ExpectationCounter("a test counter");
aCounter.setExpected(1);
aCounter.setFailOnVerify();
aCounter.inc();
aCounter.inc();
AssertMo.assertVerifyFails(aCounter);
}
public void testFailure() {
ExpectationCounter e = new ExpectationCounter("");
e.setExpected(1);
AssertMo.assertVerifyFails(e);
}
public void testFlushActual() {
ExpectationCounter e = new ExpectationCounter("");
e.inc();
e.setExpected(1);
e.inc();
e.verify();
}
public void testHasNoExpectations() {
ExpectationCounter aCounter = new ExpectationCounter("a test counter");
aCounter.inc();
assertTrue("Has no expectations", !aCounter.hasExpectations());
}
public void testSuccess() {
ExpectationCounter e = new ExpectationCounter("");
e.setExpected(1);
e.inc();
e.verify();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?