001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.coerce;
016    
017    import java.util.Iterator;
018    import java.util.List;
019    
020    import org.apache.tapestry.BaseComponentTestCase;
021    import org.testng.annotations.Test;
022    
023    /**
024     * Tests for random, simple converters.
025     * 
026     * @author Howard Lewis Ship
027     * @since 4.0
028     */
029    @Test
030    public class TestMisc extends BaseComponentTestCase
031    {
032        public void testCharArrayToIteratorConverter()
033        {
034            char[] characters = "Good Morning, Tapestry!".toCharArray();
035    
036            CharArrayToIteratorConverter c = new CharArrayToIteratorConverter();
037    
038            Iterator i = (Iterator) c.convertValue(characters);
039    
040            for (int j = 0; j < characters.length; j++)
041            {
042                Character expected = new Character(characters[j]);
043                assertEquals(expected, i.next());
044            }
045            
046            assertEquals(false, i.hasNext());
047        }
048        
049        public void test_Simple_String_To_List_Converter()
050        {
051            String input = "simple";
052            
053            StringToListConverter c = new StringToListConverter();
054            
055            List conv = (List)c.convertValue(input);
056            
057            assert conv != null;
058            assert conv.size() == 1;
059            assert conv.get(0).equals(input);
060        }
061        
062        public void test_Null_String_To_List_Converter()
063        {
064            StringToListConverter c = new StringToListConverter();
065            
066            List conv = (List)c.convertValue(null);
067            
068            assert conv != null;
069            assert conv.size() == 0;
070        }
071        
072        public void test_String_To_List_Converter()
073        {
074            String input = "val1,val2,val3";
075            
076            StringToListConverter c = new StringToListConverter();
077            
078            List conv = (List)c.convertValue(input);
079            
080            assert conv != null;
081            assert conv.size() == 3;
082            assert conv.get(1).equals("val2");
083        }
084    }