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.myfaces.commons.converter;
20  
21  import javax.faces.application.FacesMessage;
22  import javax.faces.component.UIInput;
23  import javax.faces.convert.ConverterException;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.shale.test.base.AbstractJsfTestCase;
29  
30  /**
31   * @author lu4242 (latest modification by $Author: lu4242 $)
32   * @version $Revision: 684340 $ $Date: 2008-08-09 15:42:51 -0500 (Sat, 09 Aug 2008) $
33   */
34  public class BooleanConverterTest extends AbstractJsfTestCase
35  {
36  
37      private BooleanConverter converter;
38  
39      public BooleanConverterTest(String testName)
40      {
41          super(testName);
42      }
43  
44      public void setUp() throws Exception
45      {
46          super.setUp();
47          converter = new BooleanConverter();
48      }
49  
50      public void tearDown() throws Exception
51      {
52          super.tearDown();
53          converter = null;
54      }
55  
56      public static Test suite()
57      {
58          return new TestSuite(BooleanConverterTest.class);
59      }
60  
61      public void testConverterFalse()
62      {
63          UIInput input = new UIInput();
64          input.setId("txt_test");
65  
66          converter.setTrueValue("verdadero");
67          converter.setFalseValue("falso");
68  
69          try
70          {
71              //Any different to true is false.
72              Object value = converter.getAsObject(facesContext, input, "test_invalid_input");
73              assertEquals("falso", converter.getAsString(facesContext, input, value));
74          }
75          catch (ConverterException exception)
76          {
77              fail();
78          }
79      }
80      
81      public void testConverterTrueValue()
82      {
83          UIInput input = new UIInput();
84          input.setId("txt_test");
85  
86          converter.setTrueValue("verdadero");
87          converter.setFalseValue("falso");
88  
89          try
90          {
91              Object value = converter.getAsObject(facesContext, input, "verdadero");
92              assertEquals("verdadero", converter.getAsString(facesContext, input, value));
93          }
94          catch (ConverterException exception)
95          {
96              fail();            
97          }        
98      }
99  }