|
|
@ -5,7 +5,11 @@ import de.exlll.configlib.TypeComponent.ConfigurationRecordComponent;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
|
import java.lang.reflect.RecordComponent;
|
|
|
|
import java.lang.reflect.RecordComponent;
|
|
|
|
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
@ -18,7 +22,7 @@ class TypeComponentTest {
|
|
|
|
|
|
|
|
|
|
|
|
static final class C {
|
|
|
|
static final class C {
|
|
|
|
@Comment("")
|
|
|
|
@Comment("")
|
|
|
|
int field = 20;
|
|
|
|
List<String> field = List.of("20");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -28,12 +32,19 @@ class TypeComponentTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void componentType() {
|
|
|
|
void componentType() {
|
|
|
|
assertThat(COMPONENT.componentType(), equalTo(int.class));
|
|
|
|
assertThat(COMPONENT.componentType(), equalTo(List.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void componentGenericType() {
|
|
|
|
|
|
|
|
ParameterizedType type = (ParameterizedType) COMPONENT.componentGenericType();
|
|
|
|
|
|
|
|
Type argument = type.getActualTypeArguments()[0];
|
|
|
|
|
|
|
|
assertThat(argument, equalTo(String.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void componentValue() {
|
|
|
|
void componentValue() {
|
|
|
|
assertThat(COMPONENT.componentValue(new C()), is(20));
|
|
|
|
assertThat(COMPONENT.componentValue(new C()), is(List.of("20")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -52,7 +63,7 @@ class TypeComponentTest {
|
|
|
|
private static final ConfigurationRecordComponent COMPONENT =
|
|
|
|
private static final ConfigurationRecordComponent COMPONENT =
|
|
|
|
new ConfigurationRecordComponent(RECORD_COMPONENT);
|
|
|
|
new ConfigurationRecordComponent(RECORD_COMPONENT);
|
|
|
|
|
|
|
|
|
|
|
|
record R(@Comment("") float comp) {}
|
|
|
|
record R(@Comment("") Set<Integer> comp) {}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void componentName() {
|
|
|
|
void componentName() {
|
|
|
@ -61,12 +72,19 @@ class TypeComponentTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void componentType() {
|
|
|
|
void componentType() {
|
|
|
|
assertThat(COMPONENT.componentType(), equalTo(float.class));
|
|
|
|
assertThat(COMPONENT.componentType(), equalTo(Set.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void componentGenericType() {
|
|
|
|
|
|
|
|
ParameterizedType type = (ParameterizedType) COMPONENT.componentGenericType();
|
|
|
|
|
|
|
|
Type argument = type.getActualTypeArguments()[0];
|
|
|
|
|
|
|
|
assertThat(argument, equalTo(Integer.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void componentValue() {
|
|
|
|
void componentValue() {
|
|
|
|
assertThat(COMPONENT.componentValue(new R(10f)), is(10f));
|
|
|
|
assertThat(COMPONENT.componentValue(new R(Set.of(1))), is(Set.of(1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|