4 package org
.codehaus
.groovy
.grails
.web
.taglib
;
6 import java
.io
.PrintWriter
;
7 import java
.io
.StringWriter
;
8 import java
.util
.HashMap
;
11 import org
.codehaus
.groovy
.grails
.web
.taglib
.exceptions
.GrailsTagException
;
13 import junit
.framework
.TestCase
;
16 * @author graemerocher
19 public class GroovyCollectTagTests
extends TestCase
{
21 private GroovyCollectTag tag
;
22 private StringWriter sw
;
25 * @see junit.framework.TestCase#setUp()
27 protected void setUp() throws Exception
{
29 sw
= new StringWriter();
30 tag
= new GroovyCollectTag();
31 tag
.setWriter(new PrintWriter(sw
));
35 protected void tearDown() throws Exception
43 * Test method for {@link org.codehaus.groovy.grails.web.taglib.GroovyCollectTag#isBufferWhiteSpace()}.
45 public void testIsBufferWhiteSpace() {
46 assertFalse(tag
.isBufferWhiteSpace());
50 * Test method for {@link org.codehaus.groovy.grails.web.taglib.GroovyCollectTag#hasPrecedingContent()}.
52 public void testHasPrecedingContent() {
53 assertTrue(tag
.hasPrecedingContent());
57 * Test method for {@link org.codehaus.groovy.grails.web.taglib.GroovyCollectTag#doStartTag()}.
59 public void testDoStartTag() {
60 Map attrs
= new HashMap();
64 fail("can't create this tag with no [in] and [expr] attributes");
65 } catch (GrailsTagException e
) {
68 attrs
.put("\"in\"", "myObj");
69 attrs
.put("\"expr\"", " ${ it.name }");
70 tag
.setAttributes(attrs
);
71 assertFalse(tag
.attributes
.isEmpty());
73 assertEquals("myObj.collect {it.name}.each { " + System
.getProperty("line.separator"),sw
.toString());