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;
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  }