|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * wcm.io |
| 4 | + * %% |
| 5 | + * Copyright (C) 2023 wcm.io |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package io.wcm.devops.conga.generator.plugins.handlebars.helper; |
| 21 | + |
| 22 | +import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 25 | + |
| 26 | +import java.io.IOException; |
| 27 | + |
| 28 | +import org.junit.jupiter.api.BeforeEach; |
| 29 | +import org.junit.jupiter.api.Test; |
| 30 | + |
| 31 | +import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; |
| 32 | +import io.wcm.devops.conga.generator.util.PluginManagerImpl; |
| 33 | + |
| 34 | +class DisallowPropertyHelperTest { |
| 35 | + |
| 36 | + private HelperPlugin<Object> helper; |
| 37 | + |
| 38 | + @SuppressWarnings("unchecked") |
| 39 | + @BeforeEach |
| 40 | + void setUp() { |
| 41 | + helper = new PluginManagerImpl().get(DisallowPropertyHelper.NAME, HelperPlugin.class); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void testSetCase1() throws Exception { |
| 46 | + assertThrows(IOException.class, () -> { |
| 47 | + assertHelper(null, helper, "p1", new MockOptions() |
| 48 | + .withProperty("p1", "v1")); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void testSetCase2() throws Exception { |
| 54 | + IOException ex = assertThrows(IOException.class, () -> { |
| 55 | + assertHelper(null, helper, "p1", new MockOptions("Custom Error Message") |
| 56 | + .withProperty("p1", "v1") |
| 57 | + .withProperty("p2", "v2") |
| 58 | + .withProperty("p3", "v3")); |
| 59 | + }); |
| 60 | + assertEquals("Custom Error Message", ex.getMessage()); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void testNotSetCase1() throws Exception { |
| 65 | + assertHelper(null, helper, "p1", new MockOptions()); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void testNotSetCase2() throws Exception { |
| 70 | + assertHelper(null, helper, "p1", new MockOptions("Custom Error Message")); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void testNotSetCase3() throws Exception { |
| 75 | + assertHelper(null, helper, "p1", new MockOptions("Custom Error Message") |
| 76 | + .withProperty("p2", "v1")); |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments