/** Test of renderChildren method, of class Activity. */ @Test public void testCreateChildren() throws Exception { System.out.println("renderChildren"); // Setup ChildPane childPane = new ChildPane(); childPane.setChild("Child"); VBox vbox = VBoxBuilder.create().children(childPane).build(); Parent parent = new Parent(); parent.setScene(vbox); Data data = new Data(); Map<Field, Object> fieldParams = new HashMap<Field, Object>(); for (Field field : data.getClass().getDeclaredFields()) { field.setAccessible(true); fieldParams.put(field, field.get(data)); } RenderParameter renderParam = new RenderParameter(); String id = renderParam.putParam("checkForLabel", "CheckForLabel"); childPane.setId(id); parent.createChildren(fieldParams, renderParam, ValidationResult.getEmptyResult()); // Assertoin Child child = (Child) parent.getChildActivities(Child.class).get(0); assertNotNull(child); assertNotNull(child.getScene()); assertEquals(childPane, child.getScene()); assertEquals(parent, child.getParent()); VBox cvbox = (VBox) child.getScene().getChildren().get(0); assertTrue(cvbox.getChildren().get(0) instanceof Button); assertTrue(cvbox.getChildren().get(1) instanceof Label); assertEquals(data.checkForButton, ((Button) cvbox.getChildren().get(0)).getText()); assertEquals("CheckForLabel", ((Label) cvbox.getChildren().get(1)).getText()); }
@Test public void downCastAndPolymorphism() { Child child = new Child(); Parent parentReference = child; // If the result is unexpected, consider the difference between an instance and its reference assertEquals(parentReference.complain(), __); }
@Test public void upCastAndPolymorphism() { Grandparent child = new Child(); Parent parent = (Child) child; // Think about the result. Did you expect that? Why? // How is that different from above? assertEquals(parent.complain(), __); }
@Test public void shouldFireEventForUpdatedEntities() throws Exception { Parent parent = template.save(new Parent("Donald Duck")); entities.clear(); parent = template.findOne(parent.id, Parent.class); parent.name = "Mickey Mouse"; template.save(parent); assertThat(entities.size(), is(1)); assertThat((Parent) entities.get(0), is(parent)); }
@Test public void testGetDeclaredFieldsIncludingInherited() { Parent child = new Parent() { private int childField; @SuppressWarnings("unused") public int getChildField() { return childField; } }; List<Field> fields = ReflectionUtils.getDeclaredFieldsIncludingInherited(child.getClass()); boolean containsParentField = false; boolean containsChildField = false; for (Field field : fields) { if (field.getName().equals("parentField")) { containsParentField = true; } else if (field.getName().equals("childField")) { containsChildField = true; } } List<Method> methods = ReflectionUtils.getDeclaredMethodsIncludingInherited(child.getClass()); boolean containsParentMethod = false; boolean containsChildMethod = false; for (Method method : methods) { if (method.getName().equals("getParentField")) { containsParentMethod = true; } else if (method.getName().equals("getChildField")) { containsChildMethod = true; } } assertTrue("Missing parent field", containsParentField); assertTrue("Missing child field", containsChildField); assertTrue("Missing parent method", containsParentMethod); assertTrue("Missing child method", containsChildMethod); }