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  
20  package org.apache.mailet.base;
21  
22  import org.apache.mailet.base.test.FakeMailetConfig;
23  
24  import junit.framework.TestCase;
25  
26  public class MailetUtilTest extends TestCase {
27  
28      private static final String A_PARAMETER = "aParameter";
29  
30      FakeMailetConfig config;
31      
32      protected void setUp() throws Exception {
33          super.setUp();
34          config = new FakeMailetConfig();
35      }
36  
37      protected void tearDown() throws Exception {
38          super.tearDown();
39      }
40  
41      public void testGetInitParameterParameterIsTrue() {
42          assertTrue(getParameterValued("true", true));
43          assertTrue(getParameterValued("true", false));
44          assertTrue(getParameterValued("TRUE", true));
45          assertTrue(getParameterValued("TRUE", false));
46          assertTrue(getParameterValued("trUE", true));
47          assertTrue(getParameterValued("trUE", false));
48      }
49  
50      public void testGetInitParameterParameterIsFalse() {
51          assertFalse(getParameterValued("false", true));
52          assertFalse(getParameterValued("false", false));
53          assertFalse(getParameterValued("FALSE", true));
54          assertFalse(getParameterValued("FALSE", false));
55          assertFalse(getParameterValued("fALSe", true));
56          assertFalse(getParameterValued("fALSe", false));
57      }
58      
59      public void testGetInitParameterParameterDefaultsToTrue() {
60          assertTrue(getParameterValued("fals", true));
61          assertTrue(getParameterValued("TRU", true));
62          assertTrue(getParameterValued("FALSEest", true));
63          assertTrue(getParameterValued("", true));
64          assertTrue(getParameterValued("gubbins", true));
65      }
66      
67      public void testGetInitParameterParameterDefaultsToFalse() {
68          assertFalse(getParameterValued("fals", false));
69          assertFalse(getParameterValued("TRU", false));
70          assertFalse(getParameterValued("FALSEest", false));
71          assertFalse(getParameterValued("", false));
72          assertFalse(getParameterValued("gubbins", false));
73      }
74      
75      private boolean getParameterValued(String value, boolean defaultValue) {
76          config.clear();
77          config.setProperty(A_PARAMETER, value);
78          return MailetUtil.getInitParameter(config, A_PARAMETER, defaultValue);
79      }
80  }