|
| 1 | +package cn.sticki.spel.validator.jakarta.bean; |
| 2 | + |
| 3 | +import cn.sticki.spel.validator.constrain.SpelNotNull; |
| 4 | +import cn.sticki.spel.validator.jakarta.SpelValid; |
| 5 | +import cn.sticki.spel.validator.test.util.ID; |
| 6 | +import cn.sticki.spel.validator.test.util.VerifyFailedField; |
| 7 | +import cn.sticki.spel.validator.test.util.VerifyObject; |
| 8 | +import lombok.Data; |
| 9 | + |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +/** |
| 14 | + * 测试继承类 |
| 15 | + * |
| 16 | + * @author 阿杆 |
| 17 | + * @since 2025/1/23 |
| 18 | + */ |
| 19 | +public class ParentClassTestBean { |
| 20 | + |
| 21 | + @Data |
| 22 | + @SpelValid |
| 23 | + public static class Parent implements ID { |
| 24 | + |
| 25 | + private int id; |
| 26 | + |
| 27 | + @SpelNotNull(message = "parentField不能为空") |
| 28 | + private String parentField; |
| 29 | + |
| 30 | + } |
| 31 | + |
| 32 | + @Data |
| 33 | + @SpelValid |
| 34 | + public static class Child extends Parent implements ID { |
| 35 | + |
| 36 | + @SpelNotNull(message = "childField不能为空") |
| 37 | + private String childField; |
| 38 | + |
| 39 | + } |
| 40 | + |
| 41 | + public static List<VerifyObject> paramTestCase() { |
| 42 | + ArrayList<VerifyObject> result = new ArrayList<>(); |
| 43 | + |
| 44 | + // 父类测试 |
| 45 | + Parent parent1 = new Parent(); |
| 46 | + parent1.setId(1); |
| 47 | + parent1.setParentField(null); |
| 48 | + result.add(VerifyObject.of(parent1, VerifyFailedField.of(Parent::getParentField))); |
| 49 | + |
| 50 | + Parent parent2 = new Parent(); |
| 51 | + parent2.setId(2); |
| 52 | + parent2.setParentField("123"); |
| 53 | + result.add(VerifyObject.of(parent2)); |
| 54 | + |
| 55 | + // 子类测试 |
| 56 | + Child child1 = new Child(); |
| 57 | + child1.setId(1); |
| 58 | + child1.setParentField(null); |
| 59 | + child1.setChildField(null); |
| 60 | + result.add(VerifyObject.of(child1, VerifyFailedField.of(Child::getParentField, Child::getChildField))); |
| 61 | + |
| 62 | + Child child2 = new Child(); |
| 63 | + child2.setId(2); |
| 64 | + child2.setParentField("123"); |
| 65 | + child2.setChildField("123"); |
| 66 | + result.add(VerifyObject.of(child2)); |
| 67 | + |
| 68 | + return result; |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments