MappedEntity { public void call(LifecycleAction action, Object entity) { Conditions.notNull(action); Conditions.notNull(entity); if (!isLifecycle()) return; if (action.isField()) { throw new IllegalArgumentException("action is of field type (" + action.name() + ")"); } List<Method> methods = this.lifecycleMethods.get(action); callMethods(methods, entity); } MappedEntity(T transformer, Class<?> clazz); T getTransformer(); boolean isLifecycle(); boolean isPolymorphic(); Map<String, F> getFields(); Field getIdField(); void map(); void call(LifecycleAction action, Object entity); void set(LifecycleAction action, Object entity, Object value);  }
@Test void call() { TestTransformer transformer = new TestTransformer(); TestMappedEntity entity = new TestMappedEntity(transformer, LifecycleTest.class); entity.map(); LifecycleTest test = new LifecycleTest(); entity.call(LifecycleAction.BEFORE_CREATE, test); assertTrue(test.beforeCreate); entity.call(LifecycleAction.AFTER_CREATE, test); assertTrue(test.afterCreate); assertThrows(IllegalArgumentException.class, () -> entity.call(LifecycleAction.CREATED_AT, test)); assertThrows(IllegalArgumentException.class, () -> entity.call(null, test)); assertThrows(IllegalArgumentException.class, () -> entity.call(LifecycleAction.CREATED_AT, null)); LocalDateTime time = LocalDateTime.now(); assertNull(test.createdAt); entity.set(LifecycleAction.CREATED_AT, test, time); assertEquals(time, test.createdAt); assertNull(test.accessedAt); entity.set(LifecycleAction.ACCESSED_AT, test, time); assertEquals(time, test.accessedAt); assertNull(test.updatedAt); entity.set(LifecycleAction.UPDATED_AT, test, time); assertEquals(time, test.updatedAt); assertThrows(IllegalArgumentException.class, () -> entity.set(LifecycleAction.BEFORE_CREATE, test, time)); assertThrows(IllegalArgumentException.class, () -> entity.set(null, test, time)); assertThrows(IllegalArgumentException.class, () -> entity.set(LifecycleAction.BEFORE_CREATE, null, time)); InvalidLifecycleTest invalidTest = new InvalidLifecycleTest(); TestMappedEntity invalidEntity = new TestMappedEntity(transformer, InvalidLifecycleTest.class); invalidEntity.map(); assertNull(invalidTest.createdAt); invalidEntity.set(LifecycleAction.CREATED_AT, invalidTest, time); System.out.println(invalidTest.createdAt); }