1 46 47 package org.codehaus.groovy.runtime; 48 49 import groovy.util.GroovyTestCase; 50 51 import java.util.Iterator ; 52 import java.util.Map ; 53 54 55 60 public class TupleListTest extends GroovyTestCase { 61 62 public void testIterateOverTuple() throws Exception { 63 StringBuffer buffer = new StringBuffer (); 64 for (Iterator iter = InvokerHelper.asIterator(InvokerHelper.createTuple(new Object [] { "a", "b", "c" })); 65 iter.hasNext(); 66 ) { 67 Object i = iter.next(); 68 buffer.append(i); 69 } 70 71 assertEquals("buffer", "abc", buffer.toString()); 72 } 73 74 public void testIterateOverList() throws Exception { 75 StringBuffer buffer = new StringBuffer (); 76 for (Iterator iter = InvokerHelper.asIterator(InvokerHelper.createList(new Object [] { "a", "b", "c" })); 77 iter.hasNext(); 78 ) { 79 Object i = iter.next(); 80 buffer.append(i); 81 } 82 83 assertEquals("buffer", "abc", buffer.toString()); 84 } 85 86 public void testCreateMap() throws Exception { 87 Map map = InvokerHelper.createMap(new Object [] {"a", "x", "b", "y"}); 88 89 assertNotNull("map", map); 90 assertEquals("size", 2, map.size()); 91 assertEquals("value of a", "x", map.get("a")); 92 assertEquals("value of b", "y", map.get("b")); 93 } 94 } 95 | Popular Tags |