Search in sources :

Example 1 with Class

use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.

the class ClassGetterNamingVerifierTest method shouldPassForModelWithMatchingGetters.

@Test
public void shouldPassForModelWithMatchingGetters() {
    Class aClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("Class").withField(FieldBuilder.fieldBuilder().withName("someField").withType(PRIMITIVE_INT).build()).withGetter(MethodBuilder.methodBuilder().withName("getSomeField").withType(PRIMITIVE_INT).build()).build();
    verifier.verify(singletonList(aClass));
}
Also used : Class(com.github.havardh.javaflow.ast.Class) Test(org.junit.jupiter.api.Test)

Example 2 with Class

use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.

the class ClassGetterNamingVerifierTest method shouldFailForModelWithGetterWithNonMatchingType.

@Test
public void shouldFailForModelWithGetterWithNonMatchingType() {
    Class aClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("Class").withField(FieldBuilder.fieldBuilder().withName("someField").withType(PRIMITIVE_INT).build()).withGetter(MethodBuilder.methodBuilder().withName("getSomeField").withType(PRIMITIVE_DOUBLE).build()).build();
    AggregatedException exception = assertThrows(AggregatedException.class, () -> verifier.verify(singletonList(aClass)));
    assertThat(exception.getExceptions(), hasSize(1));
}
Also used : Class(com.github.havardh.javaflow.ast.Class) AggregatedException(com.github.havardh.javaflow.exceptions.AggregatedException) Test(org.junit.jupiter.api.Test)

Example 3 with Class

use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.

the class ClassGetterNamingVerifierTest method shouldFailAndReportMultipleFieldsPerClass.

@Test
public void shouldFailAndReportMultipleFieldsPerClass() {
    Class aClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("Class").withField(FieldBuilder.fieldBuilder().withName("fieldOne").withType(PRIMITIVE_INT).build()).withField(FieldBuilder.fieldBuilder().withName("fieldTwo").withType(PRIMITIVE_INT).build()).withGetter(MethodBuilder.methodBuilder().withName("getFieldOnes").withType(PRIMITIVE_INT).build()).withGetter(MethodBuilder.methodBuilder().withName("getFieldTwos").withType(PRIMITIVE_INT).build()).build();
    AggregatedException exception = assertThrows(AggregatedException.class, () -> verifier.verify(singletonList(aClass)));
    assertThat(exception.getExceptions(), hasSize(2));
}
Also used : Class(com.github.havardh.javaflow.ast.Class) AggregatedException(com.github.havardh.javaflow.exceptions.AggregatedException) Test(org.junit.jupiter.api.Test)

Example 4 with Class

use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.

the class ClassGetterNamingVerifierTest method shouldFailForModelWithGetterWithNonMatchingName.

@Test
public void shouldFailForModelWithGetterWithNonMatchingName() {
    Class aClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("Class").withField(FieldBuilder.fieldBuilder().withName("someField").withType(PRIMITIVE_INT).build()).withGetter(MethodBuilder.methodBuilder().withName("getSomeFields").withType(PRIMITIVE_INT).build()).build();
    AggregatedException exception = assertThrows(AggregatedException.class, () -> verifier.verify(singletonList(aClass)));
    assertThat(exception.getExceptions(), hasSize(1));
}
Also used : Class(com.github.havardh.javaflow.ast.Class) AggregatedException(com.github.havardh.javaflow.exceptions.AggregatedException) Test(org.junit.jupiter.api.Test)

Example 5 with Class

use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.

the class MemberFieldsPresentVerifierTest method shouldPassForBuiltInTypes.

@Test
public void shouldPassForBuiltInTypes() {
    Class aClass = ClassBuilder.classBuilder().withName("Test1").withField(fieldBuilder().withName("name").withType(TypeBuilder.type().withName(CanonicalName.fromString("java.lang.String")).build()).build()).build();
    verifier.verify(singletonList(aClass));
}
Also used : Class(com.github.havardh.javaflow.ast.Class) Test(org.junit.jupiter.api.Test)

Aggregations

Class (com.github.havardh.javaflow.ast.Class)11 Test (org.junit.jupiter.api.Test)10 AggregatedException (com.github.havardh.javaflow.exceptions.AggregatedException)5 Field (com.github.havardh.javaflow.ast.Field)2 Parent (com.github.havardh.javaflow.ast.Parent)2 Type (com.github.havardh.javaflow.ast.Type)2 MissingTypeException (com.github.havardh.javaflow.exceptions.MissingTypeException)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 CanonicalName (com.github.havardh.javaflow.model.CanonicalName)1 TypeMap (com.github.havardh.javaflow.model.TypeMap)1 Objects.isObject (com.github.havardh.javaflow.phases.writer.flow.converter.definitions.Objects.isObject)1 Primitives.isPrimitive (com.github.havardh.javaflow.phases.writer.flow.converter.definitions.Primitives.isPrimitive)1 Lists.concat (com.github.havardh.javaflow.util.Lists.concat)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1