Skip to content

Commit

Permalink
增加测试覆盖率
Browse files Browse the repository at this point in the history
  • Loading branch information
leaderli committed Jul 23, 2024
1 parent 0aa53f9 commit 10a4257
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,17 @@ public Lira<LiTuple<F, Annotation>> relatives(AnnotatedElement annotatedElement)
.swap() // swap to human readable
)
.assertTrue(a ->
// if the annotated-annotation with meta, and meta's metaFunction first generic-type is
// not same the annotated-annotation
TypeUtil.resolve2Parameterized(a._1.getClass(), MetaFunction.class).getActualClassArgument()
.filter(annotatedByMeta -> annotatedByMeta == a._2.annotationType())
{
// if the annotated-annotation with meta, and meta's metaFunction first generic-type is
// not same the annotated-annotation
return TypeUtil.resolve2Parameterized(a._1.getClass(), MetaFunction.class).getActualClassArgument()
.filter(annotatedByMeta -> annotatedByMeta == a._2.annotationType());

}, a -> {

String expect = TypeUtil.resolve2Parameterized(a._1.getClass(), MetaFunction.class).getActualClassArgument().get() + "";
return "\r\nexpect:" + expect + "\r\nactual:" + a._2.annotationType();
}
);

}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.leaderli.litool.core.type;

import io.leaderli.litool.core.meta.LiTuple;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.lang.annotation.*;

class MetaAnnotationTest {


@Test
void test() {

MetaAnnotation<Meta, IntValue> metaAnnotation = new MetaAnnotation<>(Meta.class, IntValue.class);
LiTuple<IntValue, Annotation> tuple = metaAnnotation.relative(Bean.class).get();
Assertions.assertEquals(A1.class, tuple._2.annotationType());
tuple = metaAnnotation.relative(Bean2.class).get();
Assertions.assertEquals(A1.class, tuple._2.annotationType());

}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE})
private @interface Meta {
Class<IntValue> value() default IntValue.class;
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Meta
private @interface A1 {

int value() default 0;
}

private static class IntValue implements MetaFunction<A1, Integer, Integer> {

@Override
public Integer apply(A1 a1, Integer integer) {
return a1.value();
}
}

@A1
private static class Bean {

}

@A1(1)
private static class Bean2 {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ void isNumber() {
Assertions.assertTrue(PrimitiveEnum.isNumber(1.0));
Assertions.assertTrue(PrimitiveEnum.isNumber(1.f));
Assertions.assertFalse(PrimitiveEnum.isNumber((Object) null));

Assertions.assertTrue(PrimitiveEnum.isNumber(int.class));
Assertions.assertTrue(PrimitiveEnum.isNumber(Integer.class));

Assertions.assertFalse(PrimitiveEnum.isNumber(char.class));

Assertions.assertThrows(IllegalStateException.class, () -> PrimitiveEnum.CHAR.read("abc"));
}

@Test
Expand All @@ -74,6 +81,15 @@ void get() throws NoSuchMethodException {
Type get = TypeUtil.resolve(type, Supplier.class.getMethod("get").getGenericReturnType());
Assertions.assertSame(PrimitiveEnum.INT, PrimitiveEnum.get(get));

for (PrimitiveEnum value : PrimitiveEnum.values()) {
Assertions.assertSame(value, PrimitiveEnum.get(value.wrapper));
value.read(1);
value.read(null);
if (PrimitiveEnum.isNumber(value)) {

Assertions.assertThrows(IllegalStateException.class, () -> value.read("abc"));
}
}
}

}

0 comments on commit 10a4257

Please sign in to comment.