1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  package org.basepom.mojo.propertyhelper;
16  
17  import static org.basepom.mojo.propertyhelper.IgnoreWarnFailCreate.checkIgnoreWarnFailCreateState;
18  import static org.junit.jupiter.api.Assertions.assertFalse;
19  import static org.junit.jupiter.api.Assertions.assertSame;
20  import static org.junit.jupiter.api.Assertions.assertThrows;
21  
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  
25  
26  public class TestIgnoreWarnFailCreate {
27  
28      @Test
29      public void testValid() {
30          IgnoreWarnFailCreate value = IgnoreWarnFailCreate.forString("fail");
31          assertSame(IgnoreWarnFailCreate.FAIL, value);
32  
33          value = IgnoreWarnFailCreate.forString("warn");
34          assertSame(IgnoreWarnFailCreate.WARN, value);
35  
36          value = IgnoreWarnFailCreate.forString("ignore");
37          assertSame(IgnoreWarnFailCreate.IGNORE, value);
38  
39          value = IgnoreWarnFailCreate.forString("create");
40          assertSame(IgnoreWarnFailCreate.CREATE, value);
41      }
42  
43      @Test
44      public void testValidCases() {
45          IgnoreWarnFailCreate value = IgnoreWarnFailCreate.forString("fail");
46          assertSame(IgnoreWarnFailCreate.FAIL, value);
47  
48          value = IgnoreWarnFailCreate.forString("FAIL");
49          assertSame(IgnoreWarnFailCreate.FAIL, value);
50  
51          value = IgnoreWarnFailCreate.forString("Fail");
52          assertSame(IgnoreWarnFailCreate.FAIL, value);
53  
54          value = IgnoreWarnFailCreate.forString("FaIl");
55          assertSame(IgnoreWarnFailCreate.FAIL, value);
56      }
57  
58      @Test
59      public void testBadValue() {
60          assertThrows(IllegalArgumentException.class, () -> IgnoreWarnFailCreate.forString("foobar"));
61      }
62  
63      @Test
64      public void testNullValue() {
65          assertThrows(IllegalArgumentException.class, () -> IgnoreWarnFailCreate.forString(null));
66      }
67  
68      @Test
69      public void testCheckState() {
70          boolean value = checkIgnoreWarnFailCreateState(true, IgnoreWarnFailCreate.FAIL,  () -> "", () -> "");
71          assertFalse(value);
72  
73          value = checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.IGNORE,  () -> "", () -> "");
74          assertFalse(value);
75  
76          value = checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.WARN,  () -> "", () -> "");
77          assertFalse(value);
78  
79          value = checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.CREATE,  () -> "", () -> "");
80          Assertions.assertTrue(value);
81      }
82  
83      @Test
84      public void testCheckStateFail() {
85          assertThrows(IllegalStateException.class, () -> checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.FAIL,  () -> "", () -> ""));
86      }
87  }