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.describe;
016    
017    import org.apache.tapestry.IMarkupWriter;
018    import org.apache.tapestry.IRequestCycle;
019    import org.testng.annotations.Test;
020    
021    /**
022     * Tests for {@link ObjectArrayRenderStrategy}.
023     * 
024     * @author Howard M. Lewis Ship
025     * @since 4.0
026     */
027    @Test
028    public class ObjectArrayRenderStrategyTest extends BaseDescribeTestCase
029    {
030        public void testEmpty()
031        {
032            Object[] array = new Object[0];
033    
034            IMarkupWriter writer = newWriter();
035            IRequestCycle cycle = newCycle();
036    
037            writer.begin("em");
038            writer.print("empty list");
039            writer.end();
040    
041            replay();
042    
043            new ObjectArrayRenderStrategy().renderObject(array, writer, cycle);
044    
045            verify();
046        }
047    
048        public void testNonEmpty()
049        {
050            Object o1 = new Object();
051            Object o2 = new Object();
052    
053            Object array = new Object[]
054            { o1, o2 };
055    
056            IMarkupWriter writer = newWriter();
057            IRequestCycle cycle = newCycle();
058            RenderStrategy strategy = newMock(RenderStrategy.class);
059    
060            // Alas; this doesn't *prove* that the code executes
061            // in the right order, just that the messages for
062            // each mock execute in the right order. We'll
063            // trust that and the code and hope for the best.
064    
065            writer.begin("ul");
066            writer.begin("li");
067    
068            strategy.renderObject(o1, writer, cycle);
069    
070            writer.end();
071            writer.begin("li");
072    
073            strategy.renderObject(o2, writer, cycle);
074    
075            writer.end();
076            writer.end();
077    
078            replay();
079    
080            ObjectArrayRenderStrategy subject = new ObjectArrayRenderStrategy();
081    
082            subject.setRenderStrategy(strategy);
083    
084            subject.renderObject(array, writer, cycle);
085    
086            verify();
087        }
088    
089        public void testNullInArray()
090        {
091            Object[] array =
092            { null };
093    
094            IMarkupWriter writer = newWriter();
095            IRequestCycle cycle = newCycle();
096    
097            writer.begin("ul");
098            writer.begin("li");
099            writer.begin("em");
100            writer.print("<NULL>");
101            writer.end();
102            writer.end();
103            writer.end();
104    
105            replay();
106    
107            new ObjectArrayRenderStrategy().renderObject(array, writer, cycle);
108    
109            verify();
110        }
111    }