public static void main(String[] args) { BaseClass a = new BaseClass(5); DerivedClass b = new DerivedClass(5, 8); DerivedClass c = new DerivedClass(5, 8); System.out.println("b.equals(c): " + b.equals(c)); System.out.println("a.equals(b): " + a.equals(b)); System.out.println("b.equals(a): " + b.equals(a)); }
@Test public void mockFieldWithCapturingLimitedToOneInstance() { new NonStrictExpectations() { { mock2.getStr(); result = "mocked"; } }; assertNull(preexistingInstance.getStr()); BaseClass service1 = new DerivedClass("test 1"); assertNull(service1.str); assertEquals("mocked", service1.getStr()); BaseClass service2 = new BaseClass("test 2"); assertNull(service2.str); assertNull(service2.getStr()); new Verifications() { { mock2.getStr(); times = 1; preexistingInstance.getStr(); times = 1; } }; }
@BeforeClass public static void createAndUseInstancesBeforeCapturingIsInEffect() { assertEquals(1, new ServiceImpl().doSomething()); preexistingInstance = new DerivedClass(); assertEquals("", preexistingInstance.getStr()); assertEquals("test1", new DerivedClass("test1").getStr()); }