View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
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  }