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