Skip to content

Commit

Permalink
test: create fieldmetadta scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Jul 31, 2023
1 parent 85e0eac commit 2ed7709
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


import jakarta.nosql.Column;
import org.assertj.core.api.Assertions;
import org.eclipse.jnosql.mapping.Convert;
import org.eclipse.jnosql.mapping.Embeddable;
import org.eclipse.jnosql.mapping.VetedConverter;
Expand All @@ -27,9 +28,15 @@
import org.junit.jupiter.api.Test;

import jakarta.inject.Inject;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.eclipse.jnosql.mapping.metadata.MappingType.COLLECTION;
import static org.eclipse.jnosql.mapping.metadata.MappingType.DEFAULT;
Expand Down Expand Up @@ -145,16 +152,39 @@ public void shouldUserFieldWriter() {
assertEquals(forClass.barClass, barClass.read(forClass));
}

@Test
public void shouldReadFromAnnotation(){
EntityMetadata entityMetadata = classConverter.create(ForClass.class);
List<FieldMetadata> fields = entityMetadata.fields();

FieldMetadata field = fields.stream()
.filter(f -> "string".equals(f.fieldName())).findFirst().get();

var value = field.value(Custom.class);
Assertions.assertThat(value)
.isNotEmpty()
.get().isEqualTo("customAnnotationValue");
}

public void shouldReturnEmptyWhenThereIsNotAnnotation(){}

public void shouldReturnEmptyWhenThereIsValueMethod(){

}


public static class ForClass {

@Column("stringTypeAnnotation")
@Custom("customAnnotationValue")
private String string;

@Column("listAnnotation")
@Custom2
private List<String> list;

@Column("mapAnnotation")
@Custom3
private Map<String, String> map;


Expand All @@ -169,4 +199,18 @@ public static class BarClass {
private Integer integer;
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface Custom{
String value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface Custom2 {
}

public @interface Custom3 {
}

}

0 comments on commit 2ed7709

Please sign in to comment.