JMockitまとめた。
チュートリアルをまとめてみた。
Javaとか、Rubyとか、気が向いたときに、だらだらと。
@Cascading SocketChannel channel; @Test public void testChannel() { new NonStrictExpectaions() {{ channel.socket().getPort(); result = 1024; }} assertThat(channel.socket().getPort(), is(1024)); }
@Test public void test() { for (int i = 0; i < 10; i++) { final Dependency d = new Dependency(); new NonStrictExpectations(d) {{ d.someMethod(); result = "foo"; }}; list.add(d); } }
@Test public void test() { new NonStrictExcpectaions() { dep1.foo(); result = 1; dep2.bar(dep1.foo()); result = 2; // ←ここでdep1.foo()を呼ぶとおかしくなる } assertThat(dep1.foo(), is(1)); // ←NullPointerExceptionが発生する。 } この場合dep2.bar(anyInt)のようにすると通る。