1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.propertyhelper.definitions;
16
17 import static org.junit.jupiter.api.Assertions.assertThrows;
18
19 import org.basepom.mojo.propertyhelper.Field;
20 import org.basepom.mojo.propertyhelper.FieldContext;
21 import org.basepom.mojo.propertyhelper.ValueCache;
22
23 import java.util.UUID;
24
25 import org.junit.jupiter.api.Assertions;
26 import org.junit.jupiter.api.Test;
27
28
29 public class TestElementDefinition {
30
31 @Test
32 public void testValidId() {
33 final BasicDefinition fieldDefinition = new BasicDefinition();
34
35 fieldDefinition.id = "hello";
36 fieldDefinition.check();
37 }
38
39 @Test
40 public void testUnsetId() {
41 assertThrows(IllegalStateException.class, () -> {
42 final BasicDefinition fieldDefinition = new BasicDefinition();
43 fieldDefinition.check();
44 });
45 }
46
47 @Test
48 public void testBlankId() {
49 assertThrows(IllegalStateException.class, () -> {
50 final BasicDefinition fieldDefinition = new BasicDefinition();
51 fieldDefinition.check();
52 });
53 }
54
55 @Test
56 public void testDefaults() {
57 final String id = UUID.randomUUID().toString();
58 final BasicDefinition fieldDefinition = new BasicDefinition();
59 fieldDefinition.id = id;
60 fieldDefinition.check();
61 Assertions.assertEquals(id, fieldDefinition.getId());
62 Assertions.assertFalse(fieldDefinition.isSkip());
63 }
64
65 public static class BasicDefinition extends FieldDefinition<String> {
66
67 public BasicDefinition() {
68 }
69
70 @Override
71 public Field<String, BasicDefinition> createField(FieldContext context, ValueCache valueCache) {
72 throw new UnsupportedOperationException();
73 }
74 }
75 }