use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithGetter_methodContainsJavaDoc_noSetter.
@Test
public void generateClassWithGetter_methodContainsJavaDoc_noSetter() {
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("name");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
propertyData.setDescription("This is the name property of the component.");
propertyData.setReadOnly(true);
componentMetadata.setProperties(Collections.singletonList(propertyData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("No getter found", generatedClass.contains("public String getName()"));
Assert.assertFalse("Found setter even if it shouldn't exist", generatedClass.contains("setName"));
Assert.assertTrue("Method javaDoc was not found", generatedClass.contains("* " + propertyData.getDescription()));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsGetterAndRelatedChangeEvent_getterContainsSynchronizeAnnotation.
@Test
public void classContainsGetterAndRelatedChangeEvent_getterContainsSynchronizeAnnotation() {
ComponentPropertyData property = new ComponentPropertyData();
property.setName("someproperty");
property.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Collections.singletonList(property));
ComponentEventData event = new ComponentEventData();
event.setName("someproperty-changed");
componentMetadata.setEvents(Collections.singletonList(event));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertTrue("Wrong getter definition. It should contains @Synchronize(property = \"somepropery\", value = \"someproperty-changed\")", generatedClass.contains("@Synchronize(property = \"someproperty\", value = \"someproperty-changed\") " + "public String getSomeproperty() {"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithStringGetterAndNonFluentSetter_setterSetsEmptyForNullValue.
@Test
public void generateClassWithStringGetterAndNonFluentSetter_setterSetsEmptyForNullValue() {
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("name");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
propertyData.setDescription("This is the name property of the component.");
componentMetadata.setProperties(Collections.singletonList(propertyData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("No setter found", generatedClass.contains("public void setName(String name)"));
Assert.assertTrue("Setter doesn't check for null value", generatedClass.contains(propertyData.getName() + " == null ? \"\" : " + propertyData.getName()));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithGetterJavaDocBlock_methodContainsJavaDocWithAtCodeWrap.
@Test
public void generateClassWithGetterJavaDocBlock_methodContainsJavaDocWithAtCodeWrap() {
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("name");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
propertyData.setDescription("This is the ```<input value=\"name\">``` property of the component.");
propertyData.setReadOnly(true);
componentMetadata.setProperties(Collections.singletonList(propertyData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("No getter found", generatedClass.contains("public String getName()"));
Assert.assertTrue("Method javaDoc was not found", generatedClass.contains("* This is the {@code <input value=\"name\">} property of the component."));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsValueProperty_generatedSetValuePreventsSettingTheSameValue.
@Test
public void componentContainsValueProperty_generatedSetValuePreventsSettingTheSameValue() {
ComponentPropertyData property = new ComponentPropertyData();
property.setName("value");
property.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Collections.singletonList(property));
ComponentEventData event = new ComponentEventData();
event.setName("value-changed");
componentMetadata.setEvents(Collections.singletonList(event));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertTrue(generatedClass.contains("@Override public void setValue(String value) {" + " Objects.requireNonNull(value, \"value cannot be null\");" + " if (!Objects.equals(value, getValue())) {"));
Assert.assertTrue(generatedClass.contains("@Override public String getEmptyValue() { return \"\"; }"));
}
Aggregations