KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > example > haiku > HaikuValidatorIoHandlerTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */

19 package org.apache.mina.example.haiku;
20
21 import org.apache.mina.common.IoHandler;
22 import org.apache.mina.common.IoSession;
23 import org.jmock.Mock;
24 import org.jmock.MockObjectTestCase;
25
26 /**
27  * @author Apache Mina Project (dev@mina.apache.org)
28  * @version $Rev: $, $Date: $
29  */

30 public class HaikuValidatorIoHandlerTest extends MockObjectTestCase {
31     private IoHandler handler;
32
33     @Override JavaDoc
34     protected void setUp() throws Exception JavaDoc {
35         super.setUp();
36
37         handler = new HaikuValidatorIoHandler();
38     }
39
40     public void testValidHaiku() throws Exception JavaDoc {
41         Mock session = mock(IoSession.class);
42         session.expects(once()).method("write").with(eq("HAIKU!"));
43         IoSession sessionProxy = (IoSession) session.proxy();
44
45         handler.messageReceived(sessionProxy, new Haiku(
46                 "Oh, I drank too much.", "Why, oh why did I sign up",
47                 "For an eight thirty?"));
48     }
49
50     public void testInvalidHaiku() throws Exception JavaDoc {
51         Mock session = mock(IoSession.class);
52         session.expects(once()).method("write").with(
53                 eq("NOT A HAIKU: phrase 1, 'foo' had 1 syllables, not 5"));
54         IoSession sessionProxy = (IoSession) session.proxy();
55
56         handler.messageReceived(sessionProxy,
57                 new Haiku("foo", "a haiku", "poo"));
58     }
59 }
60
Popular Tags