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