共有 0 个贴子
没有任何数据可供显示
| 开源项目社区 | 当前位置 : |
|
| www.trustie.net/open_source_projects | 主页 > 开源项目社区 > sm4java |
|
sm4java
|
| 0 | 0 | 0 |
| 贡献者 | 讨论 | 代码提交 |
sm4j is a dynamic mocking API, such as EasyMock or jMock, but in a simple manner. Compiled JAR sizes about 10Kb, without any kind of dependencies. sm4j allows you to define mock expectations declaretively, using a simple DSL in a fluent style.
import static org.gro.sm4j.Mocky.*;
import static org.junit.Assert.*;
import org.junit.Test;
interface IMul {
int mul(int a, Long b);
String counter();
}
public class DidacticTest {
@Test
public void test() {
final IMul i = createMock(IMul.class);
thenReturn(2).when(i).mul(anyInt(), eq(0L));
thenReturn(9).when(i).mul(eq(0), anyLong());
thenReturn(15).when(i).mul(5, 3L);
thenReturnSeq("one", "two", "three").when(i).counter();
replay(i);
assertEquals(2, i.mul(10, 0L));
assertEquals(9, i.mul(0, 5L));
assertEquals(15, i.mul(5, 3L));
assertEquals("one", i.counter());
assertEquals("two", i.counter());
assertEquals("three", i.counter());
verify(i);
}
}
标签: