001    // Copyright 2004, 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.components;
016    
017    import static org.easymock.EasyMock.expect;
018    
019    import org.apache.tapestry.BaseComponentTestCase;
020    import org.apache.tapestry.IMarkupWriter;
021    import org.apache.tapestry.IRequestCycle;
022    import org.testng.annotations.Test;
023    
024    /**
025     * Tests for {@link org.apache.tapestry.components.RenderBlock} component.
026     * 
027     * @author Howard M. Lewis Ship
028     * @since 4.0
029     */
030    @Test
031    public class TestRenderBlock extends BaseComponentTestCase
032    {
033        public void testNullBlock()
034        {
035            RenderBlock rb = (RenderBlock) newInstance(RenderBlock.class);
036            
037            IMarkupWriter writer = newWriter();
038            IRequestCycle cycle = newMock(IRequestCycle.class);
039            
040            expect(cycle.renderStackPush(rb)).andReturn(rb);
041            
042            expect(cycle.renderStackPop()).andReturn(rb);
043            
044            replay();
045    
046            rb.render(writer, cycle);
047    
048            verify();
049        }
050    
051        public void testNonNullBlock()
052        {
053            Block b = (Block)newInstance(Block.class);
054    
055            RenderBlock rb = newInstance(RenderBlock.class, 
056                    new Object[] { "block", b });
057            
058            IMarkupWriter writer = newWriter();
059            IRequestCycle cycle = newMock(IRequestCycle.class);
060            
061            expect(cycle.renderStackPush(rb)).andReturn(rb);
062            
063            b.renderForComponent(writer, cycle, rb);
064    
065            expect(cycle.renderStackPop()).andReturn(rb);
066            
067            replay();
068    
069            rb.render(writer, cycle);
070    
071            verify();
072        }
073    }