@Test(expected = RuntimeException.class) // Uses of JMockit API: 2 public void stubVoidMethodsWithExceptions() { new Expectations() { { // void/non-void methods are handled the same way, with a consistent API: mockedList.clear(); result = new RuntimeException(); } }; mockedList.clear(); }
@Test // Uses of JMockit API: 2 public void stubbingVoidMethods() { // The API is consistent, so this is the same as for non-void methods: new Expectations() { { mockedList.clear(); result = new RuntimeException(); } }; try { // Following throws RuntimeException: mockedList.clear(); fail(); } catch (RuntimeException ignore) { } }
@Before public void setUp() throws Exception { additionalTables.clear(); tableName = tablePrefix + "_" + testName.getMethodName(); recreateTable(tableName); }
@Test public void loadEmployeeEnhanced() { SienaFixtures.loadModels("data2.yml"); // Bob EmployeeEnhanced bob = EmployeeEnhanced.all().filter("firstName", "Bob").get(); assertNotNull(bob); assertEquals("Bob", bob.firstName); assertEquals("Smith", bob.lastName); assertEquals("password1", bob.pwd); assertEquals("{\"alpha1\": \"beta1\"}", bob.contactInfo.toString()); // profileImage assertEquals("filename1.ext", bob.profileImage.filename); assertEquals("title1", bob.profileImage.title); assertEquals(1, bob.profileImage.views); assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.profileImage.itemEnum); // otherImages[0] assertEquals("filename1.ext", bob.otherImages.get(0).filename); assertEquals("title1", bob.otherImages.get(0).title); assertEquals(1, bob.otherImages.get(0).views); assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.otherImages.get(0).itemEnum); // otherImages[1] assertEquals("filename2.ext", bob.otherImages.get(1).filename); assertEquals("title2", bob.otherImages.get(1).title); assertEquals(2, bob.otherImages.get(1).views); assertEquals(EmployeeEnhanced.MyEnum.VAL2, bob.otherImages.get(1).itemEnum); // stillImages[test1] assertEquals("filename1.ext", bob.stillImages.get("test1").filename); assertEquals("title1", bob.stillImages.get("test1").title); assertEquals(1, bob.stillImages.get("test1").views); assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.stillImages.get("test1").itemEnum); // stillImages[test2] assertEquals("filename2.ext", bob.stillImages.get("test2").filename); assertEquals("title2", bob.stillImages.get("test2").title); assertEquals(2, bob.stillImages.get("test2").views); assertEquals(EmployeeEnhanced.MyEnum.VAL2, bob.stillImages.get("test2").itemEnum); // items[1] assertEquals("alpha1", bob.items.get(0).item); assertEquals("beta1", bob.items.get(0).item2); assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.items.get(0).itemEnum); // items[2] assertEquals("alpha2", bob.items.get(1).item); assertEquals("beta2", bob.items.get(1).item2); assertEquals(EmployeeEnhanced.MyEnum.VAL2, bob.items.get(1).itemEnum); // enumField assertEquals(EmployeeEnhanced.MyEnum.VAL3, bob.enumField); // John EmployeeEnhanced john = EmployeeEnhanced.all().filter("firstName", "John").get(); assertNotNull(john); assertEquals("John", john.firstName); assertEquals("Doe", john.lastName); assertEquals("password2", john.pwd); assertEquals("{\"alpha2\": \"beta2\"}", john.contactInfo.toString()); assertEquals("filename2.ext", john.profileImage.filename); assertEquals("title2", john.profileImage.title); assertEquals(2, john.profileImage.views); assertEquals(EmployeeEnhanced.MyEnum.VAL2, john.profileImage.itemEnum); assertEquals(bob.id, john.boss.id); // emp1 EmployeeEnhanced emp1 = EmployeeEnhanced.all().filter("firstName", "emp1").get(); assertNotNull(emp1); // emp2 EmployeeEnhanced emp2 = EmployeeEnhanced.all().filter("firstName", "emp2").get(); assertNotNull(emp2); // boss EmployeeEnhanced boss = EmployeeEnhanced.all(EmployeeEnhanced.class).filter("firstName", "boss").get(); assertNotNull(boss); List<EmployeeEnhanced> emps = boss.employees.fetch(); assertEquals(emp1.id, emps.get(0).id); assertEquals(emp2.id, emps.get(1).id); assertEquals(emp1.boss.id, boss.id); assertEquals(emp2.boss.id, boss.id); // query wrapper Query<EmployeeEnhanced> q = EmployeeEnhanced.all().getWrappedQuery(); emps = q.filter("firstName", "boss").fetch(); assertEquals(boss, emps.get(0)); // enhanced functions tests Batch<EmployeeEnhanced> b = EmployeeEnhanced.batch().getWrappedBatch(); List<EmployeeEnhanced> emps2 = b.getByKeys(bob.id, john.id, boss.id, emp1.id, emp2.id); assertEquals(bob, emps2.get(0)); assertEquals(john, emps2.get(1)); assertEquals(boss, emps2.get(2)); assertEquals(emp1, emps2.get(3)); assertEquals(emp2, emps2.get(4)); emps2.clear(); emps2 = EmployeeEnhanced.batch().getByKeys(bob.id, john.id, boss.id, emp1.id, emp2.id); assertEquals(bob, emps2.get(0)); assertEquals(john, emps2.get(1)); assertEquals(boss, emps2.get(2)); assertEquals(emp1, emps2.get(3)); assertEquals(emp2, emps2.get(4)); emps2.clear(); emps2 = EmployeeEnhanced.findAll(); assertEquals(bob, emps2.get(0)); assertEquals(john, emps2.get(1)); assertEquals(emp1, emps2.get(2)); assertEquals(emp2, emps2.get(3)); assertEquals(boss, emps2.get(4)); assertEquals(bob, EmployeeEnhanced.findById(bob.id)); assertEquals(bob, EmployeeEnhanced.getByKey(bob.id)); assertEquals(5, EmployeeEnhanced.count()); EmployeeEnhanced.deleteAll(); assertEquals(0, EmployeeEnhanced.count()); }