View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.ear;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  
26  /**
27   * @author Stephane Nicoll
28   */
29  public class EnvEntryTest {
30  
31      public static final String DESCRIPTION = "description";
32  
33      public static final String NAME = "name";
34  
35      public static final String TYPE = Integer.class.getName();
36  
37      public static final String VALUE = "34";
38  
39      public static final String LOOKUP_NAME = "lookupName";
40  
41      @Test
42      public void createComplete() {
43          final EnvEntry envEntry = new EnvEntry(DESCRIPTION, NAME, TYPE, VALUE, LOOKUP_NAME);
44          assertEnvEntry(envEntry, DESCRIPTION, NAME, TYPE, VALUE, LOOKUP_NAME);
45      }
46  
47      @Test
48      public void createWithoutTypeButValue() {
49          final EnvEntry envEntry = new EnvEntry(null, NAME, null, VALUE, LOOKUP_NAME);
50          assertEnvEntry(envEntry, null, NAME, null, VALUE, LOOKUP_NAME);
51      }
52  
53      @Test(expected = IllegalArgumentException.class)
54      public void createWithoutName() {
55          new EnvEntry(DESCRIPTION, null, TYPE, VALUE, LOOKUP_NAME);
56      }
57  
58      @Test(expected = IllegalArgumentException.class)
59      public void createWithEmptyName() {
60          new EnvEntry(DESCRIPTION, "", TYPE, VALUE, LOOKUP_NAME);
61      }
62  
63      @Test(expected = IllegalArgumentException.class)
64      public void createWithNullTypeAndNoValue() {
65          new EnvEntry(DESCRIPTION, NAME, null, null, LOOKUP_NAME);
66      }
67  
68      @Test(expected = IllegalArgumentException.class)
69      public void createWithEmptyTypeAndNoValue() {
70          new EnvEntry(DESCRIPTION, NAME, "", null, LOOKUP_NAME);
71      }
72  
73      @Test
74      public void createWithEmptyLookupName() {
75          new EnvEntry(DESCRIPTION, NAME, TYPE, VALUE, null);
76      }
77  
78      private void assertEnvEntry(
79              EnvEntry actual, String description, String name, String type, String value, String lookupName) {
80          assertNotNull("Env entry could not be null", actual);
81          assertNotNull("ToString could not be null", actual.toString());
82          assertEquals("Wrong env entry description for [" + actual + "]", description, actual.getDescription());
83          assertEquals("Wrong env entry name for [" + actual + "]", name, actual.getName());
84          assertEquals("Wrong env entry type for [" + actual + "]", type, actual.getType());
85          assertEquals("Wrong env entry value for [" + actual + "]", value, actual.getValue());
86          assertEquals("Wrong env entry value for [" + actual + "]", lookupName, actual.getLookupName());
87      }
88  }