| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.maven.plugins.ear; |
| |
| import org.junit.jupiter.api.Test; |
| |
| import static org.junit.jupiter.api.Assertions.assertEquals; |
| import static org.junit.jupiter.api.Assertions.assertNotNull; |
| import static org.junit.jupiter.api.Assertions.assertThrows; |
| |
| /** |
| * @author Stephane Nicoll |
| */ |
| class EnvEntryTest { |
| |
| private static final String DESCRIPTION = "description"; |
| |
| private static final String NAME = "name"; |
| |
| private static final String TYPE = Integer.class.getName(); |
| |
| private static final String VALUE = "34"; |
| |
| private static final String LOOKUP_NAME = "lookupName"; |
| |
| @Test |
| void createComplete() { |
| final EnvEntry envEntry = new EnvEntry(DESCRIPTION, NAME, TYPE, VALUE, LOOKUP_NAME); |
| assertEnvEntry(envEntry, DESCRIPTION, NAME, TYPE, VALUE, LOOKUP_NAME); |
| } |
| |
| @Test |
| void createWithoutTypeButValue() { |
| final EnvEntry envEntry = new EnvEntry(null, NAME, null, VALUE, LOOKUP_NAME); |
| assertEnvEntry(envEntry, null, NAME, null, VALUE, LOOKUP_NAME); |
| } |
| |
| @Test |
| void createWithoutName() { |
| assertThrows(IllegalArgumentException.class, () -> { |
| new EnvEntry(DESCRIPTION, null, TYPE, VALUE, LOOKUP_NAME); |
| }); |
| } |
| |
| @Test |
| void createWithEmptyName() { |
| assertThrows(IllegalArgumentException.class, () -> { |
| new EnvEntry(DESCRIPTION, "", TYPE, VALUE, LOOKUP_NAME); |
| }); |
| } |
| |
| @Test |
| void createWithNullTypeAndNoValue() { |
| assertThrows(IllegalArgumentException.class, () -> { |
| new EnvEntry(DESCRIPTION, NAME, null, null, LOOKUP_NAME); |
| }); |
| } |
| |
| @Test |
| void createWithEmptyTypeAndNoValue() { |
| assertThrows(IllegalArgumentException.class, () -> { |
| new EnvEntry(DESCRIPTION, NAME, "", null, LOOKUP_NAME); |
| }); |
| } |
| |
| @Test |
| void createWithEmptyLookupName() { |
| new EnvEntry(DESCRIPTION, NAME, TYPE, VALUE, null); |
| } |
| |
| private void assertEnvEntry( |
| EnvEntry actual, String description, String name, String type, String value, String lookupName) { |
| assertNotNull(actual, "Env entry could not be null"); |
| assertNotNull(actual.toString(), "ToString could not be null"); |
| assertEquals(description, actual.getDescription(), "Wrong env entry description for [" + actual + "]"); |
| assertEquals(name, actual.getName(), "Wrong env entry name for [" + actual + "]"); |
| assertEquals(type, actual.getType(), "Wrong env entry type for [" + actual + "]"); |
| assertEquals(value, actual.getValue(), "Wrong env entry value for [" + actual + "]"); |
| assertEquals(lookupName, actual.getLookupName(), "Wrong env entry value for [" + actual + "]"); |
| } |
| } |