EMMA Coverage Report (generated Mon Jul 11 13:15:38 KST 2005)
[all classes][org.apache.mina.io]

COVERAGE SUMMARY FOR SOURCE FILE [IoFilterChainTest.java]

nameclass, %method, %block, %line, %
IoFilterChainTest.java83%  (5/6)74%  (26/35)95%  (380/399)89%  (77/87)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IoFilterChainTest$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class IoFilterChainTest$TestSession100% (1/1)18%  (2/11)48%  (15/31)25%  (3/12)
close (boolean): void 0%   (0/1)0%   (0/1)0%   (0/1)
getConfig (): SessionConfig 0%   (0/1)0%   (0/2)0%   (0/1)
getFilterChain (): IoFilterChain 0%   (0/1)0%   (0/2)0%   (0/1)
getLocalAddress (): SocketAddress 0%   (0/1)0%   (0/2)0%   (0/1)
getRemoteAddress (): SocketAddress 0%   (0/1)0%   (0/2)0%   (0/1)
getScheduledWriteRequests (): int 0%   (0/1)0%   (0/2)0%   (0/1)
getTransportType (): TransportType 0%   (0/1)0%   (0/2)0%   (0/1)
isConnected (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
write (ByteBuffer, Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
IoFilterChainTest$TestSession (IoFilterChainTest): void 100% (1/1)100% (12/12)100% (2/2)
getHandler (): IoHandler 100% (1/1)100% (3/3)100% (1/1)
     
class IoFilterChainTest$TestSession$1100% (1/1)100% (7/7)95%  (59/62)93%  (14/15)
exceptionCaught (IoSession, Throwable): void 100% (1/1)86%  (18/21)75%  (3/4)
IoFilterChainTest$TestSession$1 (IoFilterChainTest$TestSession): void 100% (1/1)100% (6/6)100% (1/1)
dataRead (IoSession, ByteBuffer): void 100% (1/1)100% (7/7)100% (2/2)
dataWritten (IoSession, Object): void 100% (1/1)100% (7/7)100% (2/2)
sessionClosed (IoSession): void 100% (1/1)100% (7/7)100% (2/2)
sessionIdle (IoSession, IdleStatus): void 100% (1/1)100% (7/7)100% (2/2)
sessionOpened (IoSession): void 100% (1/1)100% (7/7)100% (2/2)
     
class IoFilterChainTest100% (1/1)100% (7/7)100% (164/164)100% (32/32)
IoFilterChainTest (): void 100% (1/1)100% (3/3)100% (2/2)
formatResult (String): String 100% (1/1)100% (41/41)100% (7/7)
run (String): void 100% (1/1)100% (75/75)100% (12/12)
setUp (): void 100% (1/1)100% (16/16)100% (4/4)
tearDown (): void 100% (1/1)100% (1/1)100% (1/1)
testChained (): void 100% (1/1)100% (24/24)100% (4/4)
testDefault (): void 100% (1/1)100% (4/4)100% (2/2)
     
class IoFilterChainTest$IoFilterChainImpl100% (1/1)100% (2/2)100% (8/8)100% (4/4)
IoFilterChainTest$IoFilterChainImpl (): void 100% (1/1)100% (3/3)100% (2/2)
doWrite (IoSession, ByteBuffer, Object): void 100% (1/1)100% (5/5)100% (2/2)
     
class IoFilterChainTest$TestFilter100% (1/1)100% (8/8)100% (134/134)100% (24/24)
IoFilterChainTest$TestFilter (IoFilterChainTest, char): void 100% (1/1)100% (9/9)100% (3/3)
dataRead (IoFilter$NextFilter, IoSession, ByteBuffer): void 100% (1/1)100% (18/18)100% (3/3)
dataWritten (IoFilter$NextFilter, IoSession, Object): void 100% (1/1)100% (18/18)100% (3/3)
exceptionCaught (IoFilter$NextFilter, IoSession, Throwable): void 100% (1/1)100% (18/18)100% (3/3)
filterWrite (IoFilter$NextFilter, IoSession, ByteBuffer, Object): void 100% (1/1)100% (19/19)100% (3/3)
sessionClosed (IoFilter$NextFilter, IoSession): void 100% (1/1)100% (17/17)100% (3/3)
sessionIdle (IoFilter$NextFilter, IoSession, IdleStatus): void 100% (1/1)100% (18/18)100% (3/3)
sessionOpened (IoFilter$NextFilter, IoSession): void 100% (1/1)100% (17/17)100% (3/3)

1/*
2 *   @(#) $Id: IoFilterChainTest.java 210062 2005-07-11 03:52:38Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.io;
20 
21import java.net.SocketAddress;
22 
23import junit.framework.Assert;
24import junit.framework.TestCase;
25 
26import org.apache.mina.common.BaseSession;
27import org.apache.mina.common.ByteBuffer;
28import org.apache.mina.common.IdleStatus;
29import org.apache.mina.common.SessionConfig;
30import org.apache.mina.common.TransportType;
31 
32/**
33 * Tests {@link AbstractIoFilterChain}.
34 * 
35 * @author Trustin Lee (trustin@apache.org)
36 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $ 
37 */
38public class IoFilterChainTest extends TestCase
39{
40    private IoFilterChainImpl chain;
41    private IoSession session;
42    private String result;
43 
44    public void setUp()
45    {
46        chain = new IoFilterChainImpl();
47        session = new TestSession();
48        result = "";
49    }
50    
51    public void tearDown()
52    {
53    }
54    
55    public void testDefault()
56    {
57        run( "HSO HDR HDW HSI HEC HSC" );
58    }
59    
60    public void testChained()
61    {
62        chain.addLast( "A", new TestFilter( 'A' ) );
63        chain.addLast( "B", new TestFilter( 'B' ) );
64        run( "ASO BSO HSO" +
65             "ADR BDR HDR" +
66             "BFW AFW ADW BDW HDW" +
67             "ASI BSI HSI" +
68             "AEC BEC HEC" +
69             "ASC BSC HSC" );
70    }
71    
72    private void run( String expectedResult )
73    {
74        chain.sessionOpened( session );
75        chain.dataRead( session, ByteBuffer.allocate( 16 ) );
76        chain.filterWrite( session, ByteBuffer.allocate( 16 ), null );
77        chain.sessionIdle( session, IdleStatus.READER_IDLE );
78        chain.exceptionCaught( session, new Exception() );
79        chain.sessionClosed( session );
80        
81        result = formatResult( result );
82        expectedResult = formatResult( expectedResult );
83        
84        System.out.println( "Expected: " + expectedResult );
85        System.out.println( "Actual:   " + result );
86        Assert.assertEquals( expectedResult, result );
87    }
88    
89    private String formatResult( String result )
90    {
91        result = result.replaceAll( "\\s", "" );
92        StringBuffer buf = new StringBuffer( result.length() * 4 / 3 );
93        for( int i = 0; i < result.length(); i++ )
94        {
95            buf.append( result.charAt( i ) );
96            if( i % 3 == 2 )
97            {
98                buf.append(' ');
99            }
100        }
101        
102        return buf.toString();
103    }
104 
105    private class TestSession extends BaseSession implements IoSession
106    {
107        private IoHandler handler = new IoHandlerAdapter()
108        {
109            public void sessionOpened(IoSession session) {
110                result += "HSO ";
111            }
112 
113            public void dataRead(IoSession session, ByteBuffer buf) {
114                result += "HDR ";
115            }
116 
117            public void dataWritten(IoSession session, Object marker) {
118                result += "HDW ";
119            }
120            
121            public void sessionIdle(IoSession session, IdleStatus status) {
122                result += "HSI ";
123            }
124 
125            public void exceptionCaught(IoSession session, Throwable cause) {
126                result += "HEC ";
127                if( cause.getClass() != Exception.class )
128                {
129                    cause.printStackTrace( System.out );
130                }
131            }
132 
133            public void sessionClosed(IoSession session) {
134                result += "HSC ";
135            }
136        };
137 
138        public IoHandler getHandler()
139        {
140            return handler;
141        }
142 
143        public void close( boolean wait )
144        {
145        }
146 
147        public void write(ByteBuffer buf, Object marker)
148        {
149        }
150 
151        public int getScheduledWriteRequests()
152        {
153            return 0;
154        }
155 
156        public TransportType getTransportType()
157        {
158            return null;
159        }
160 
161        public boolean isConnected()
162        {
163            return false;
164        }
165 
166        public SessionConfig getConfig()
167        {
168            return null;
169        }
170 
171        public SocketAddress getRemoteAddress()
172        {
173            return null;
174        }
175 
176        public SocketAddress getLocalAddress()
177        {
178            return null;
179        }
180 
181        public IoFilterChain getFilterChain()
182        {
183            return null;
184        }
185    }
186 
187    private class TestFilter implements IoFilter
188    {
189        private final char id;
190 
191        private TestFilter( char id )
192        {
193            this.id = id;
194        }
195        
196        public void sessionOpened(NextFilter nextFilter, IoSession session) {
197            result += id + "SO ";
198            nextFilter.sessionOpened( session );
199        }
200 
201        public void sessionClosed(NextFilter nextFilter, IoSession session) {
202            result += id + "SC ";
203            nextFilter.sessionClosed( session );
204        }
205 
206        public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) {
207            result += id + "SI ";
208            nextFilter.sessionIdle( session, status );
209        }
210 
211        public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
212            result += id + "EC ";
213            nextFilter.exceptionCaught( session, cause );
214        }
215 
216        public void dataRead(NextFilter nextFilter, IoSession session, ByteBuffer buf) {
217            result += id + "DR ";
218            nextFilter.dataRead( session, buf );
219        }
220 
221        public void dataWritten(NextFilter nextFilter, IoSession session, Object marker) {
222            result += id + "DW ";
223            nextFilter.dataWritten( session, marker );
224        }
225 
226        public void filterWrite(NextFilter nextFilter, IoSession session, ByteBuffer buf, Object marker) {
227            result += id + "FW ";
228            nextFilter.filterWrite( session, buf, marker );
229        }
230    }
231 
232    private static class IoFilterChainImpl extends AbstractIoFilterChain
233    {
234        protected IoFilterChainImpl()
235        {
236        }
237 
238        protected void doWrite(IoSession session, ByteBuffer buffer, Object marker)
239        {
240            dataWritten( session, marker );
241        }
242    }
243    
244}

[all classes][org.apache.mina.io]
EMMA 2.0.4217 (C) Vladimir Roubtsov