001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 * http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014
015package org.basepom.mojo.propertyhelper;
016
017import static org.basepom.mojo.propertyhelper.IgnoreWarnFailCreate.checkIgnoreWarnFailCreateState;
018import static org.junit.jupiter.api.Assertions.assertFalse;
019import static org.junit.jupiter.api.Assertions.assertSame;
020import static org.junit.jupiter.api.Assertions.assertThrows;
021
022import org.junit.jupiter.api.Assertions;
023import org.junit.jupiter.api.Test;
024
025
026public class TestIgnoreWarnFailCreate {
027
028    @Test
029    public void testValid() {
030        IgnoreWarnFailCreate value = IgnoreWarnFailCreate.forString("fail");
031        assertSame(IgnoreWarnFailCreate.FAIL, value);
032
033        value = IgnoreWarnFailCreate.forString("warn");
034        assertSame(IgnoreWarnFailCreate.WARN, value);
035
036        value = IgnoreWarnFailCreate.forString("ignore");
037        assertSame(IgnoreWarnFailCreate.IGNORE, value);
038
039        value = IgnoreWarnFailCreate.forString("create");
040        assertSame(IgnoreWarnFailCreate.CREATE, value);
041    }
042
043    @Test
044    public void testValidCases() {
045        IgnoreWarnFailCreate value = IgnoreWarnFailCreate.forString("fail");
046        assertSame(IgnoreWarnFailCreate.FAIL, value);
047
048        value = IgnoreWarnFailCreate.forString("FAIL");
049        assertSame(IgnoreWarnFailCreate.FAIL, value);
050
051        value = IgnoreWarnFailCreate.forString("Fail");
052        assertSame(IgnoreWarnFailCreate.FAIL, value);
053
054        value = IgnoreWarnFailCreate.forString("FaIl");
055        assertSame(IgnoreWarnFailCreate.FAIL, value);
056    }
057
058    @Test
059    public void testBadValue() {
060        assertThrows(IllegalArgumentException.class, () -> IgnoreWarnFailCreate.forString("foobar"));
061    }
062
063    @Test
064    public void testNullValue() {
065        assertThrows(IllegalArgumentException.class, () -> IgnoreWarnFailCreate.forString(null));
066    }
067
068    @Test
069    public void testCheckState() {
070        boolean value = checkIgnoreWarnFailCreateState(true, IgnoreWarnFailCreate.FAIL,  () -> "", () -> "");
071        assertFalse(value);
072
073        value = checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.IGNORE,  () -> "", () -> "");
074        assertFalse(value);
075
076        value = checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.WARN,  () -> "", () -> "");
077        assertFalse(value);
078
079        value = checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.CREATE,  () -> "", () -> "");
080        Assertions.assertTrue(value);
081    }
082
083    @Test
084    public void testCheckStateFail() {
085        assertThrows(IllegalStateException.class, () -> checkIgnoreWarnFailCreateState(false, IgnoreWarnFailCreate.FAIL,  () -> "", () -> ""));
086    }
087}