more tests

This commit is contained in:
wea_ondara
2022-09-08 17:20:16 +02:00
parent 703e3b1367
commit 6cdf74f351
3 changed files with 94 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ class EntityInitializer {
throw new ModelException("DbSet " + ctxField.getName() + " is missing the " + Clazz.class.getSimpleName() + " annotation");
}
if (!SerializableObject.class.isAssignableFrom(clazzAnnotation.value())) {
throw new ModelException("DbSet " + ctxField.getName() + " has a class in its " + Clazz.class.getSimpleName() + " annotation that does not inherit from " + SerializableObject.class.getSimpleName() + ": " + clazzAnnotation.value().getSimpleName()); //TODO testcase for this
throw new ModelException("DbSet " + ctxField.getName() + " has a class in its " + Clazz.class.getSimpleName() + " annotation that does not inherit from " + SerializableObject.class.getSimpleName() + ": " + clazzAnnotation.value().getSimpleName());
}
var dbSetClazz = (Class<? extends SerializableObject>) clazzAnnotation.value();
initEntity(mb, dbSetClazz, ctxField.getName(), true);
@@ -52,11 +52,11 @@ class EntityInitializer {
//e.g. class Entity { @Clazz(Entity2.class) List<Entity2> ent; @Clazz(Entity2.class) Set<Entity2> ent2; }
var clazzAnnotation = f.getAnnotation(Clazz.class);
if (clazzAnnotation == null) {
throw new ModelException("Field " + f.getClass().getSimpleName() + "::" + f.getName() + " is missing the " + Clazz.class.getSimpleName() + " annotation");
throw new ModelException("Field " + clazz.getSimpleName() + "::" + f.getName() + " is missing the " + Clazz.class.getSimpleName() + " annotation");
}
var fClazz = clazzAnnotation.value();
if (!SerializableObject.class.isAssignableFrom(fClazz)) {
throw new ModelException("Field " + f.getClass().getSimpleName() + "::" + f.getName() + " has a class in its " + Clazz.class.getSimpleName() + " annotation that does not inherit from " + SerializableObject.class.getSimpleName() + ": " + fClazz.getSimpleName()); //TODO testcase for this
throw new ModelException("Field " + clazz.getSimpleName() + "::" + f.getName() + " has a class in its " + Clazz.class.getSimpleName() + " annotation that does not inherit from " + SerializableObject.class.getSimpleName() + ": " + fClazz.getSimpleName());
}
var foundCollection = entity.fields().stream()
.filter(e -> Collection.class.isAssignableFrom(e.getField().getType())

View File

@@ -0,0 +1,45 @@
package jef.model;
import jef.DbSet;
import jef.model.annotations.Clazz;
import jef.model.annotations.Id;
import jef.serializable.SerializableObject;
import lombok.Getter;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
class EntityInitializerCollectionAnnotationClassInheritTest {
@Test
public void test() {
assertEquals("Field TestClass2::nested is missing the Clazz annotation",
assertThrowsExactly(ModelException.class, () -> ModelBuilder.from(Ctx.class)).getMessage());
}
public static class Ctx extends DbContext {
@Clazz(TestClass2.class)
private DbSet<TestClass2> objects2;
@Clazz(TestClass.class)
private DbSet<TestClass> objects;
}
@Getter
public static class TestClass2 extends SerializableObject {
@Id
public int i2 = 1;
public List<TestClass> nested;
}
@Getter
public static class TestClass extends SerializableObject {
@Id
public int i = 1;
public Object o = new Object();
public double d;
public float f;
public long l;
}
}

View File

@@ -0,0 +1,46 @@
package jef.model;
import jef.DbSet;
import jef.model.annotations.Clazz;
import jef.model.annotations.Id;
import jef.serializable.SerializableObject;
import lombok.Getter;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
class EntityInitializerCollectionAnnotationMissingTest {
@Test
public void test() {
assertEquals("Field TestClass2::nested has a class in its Clazz annotation that does not inherit from SerializableObject: int",
assertThrowsExactly(ModelException.class, () -> ModelBuilder.from(Ctx.class)).getMessage());
}
public static class Ctx extends DbContext {
@Clazz(TestClass2.class)
private DbSet<TestClass2> objects2;
@Clazz(TestClass.class)
private DbSet<TestClass> objects;
}
@Getter
public static class TestClass2 extends SerializableObject {
@Id
public int i2 = 1;
@Clazz(int.class)
public List<TestClass> nested;
}
@Getter
public static class TestClass extends SerializableObject {
@Id
public int i = 1;
public Object o = new Object();
public double d;
public float f;
public long l;
}
}