001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.mina.example.haiku; 020 021import org.apache.mina.core.service.IoHandler; 022import org.apache.mina.core.session.IoSession; 023import org.jmock.Mock; 024import org.jmock.MockObjectTestCase; 025 026/** 027 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 028 */ 029public class HaikuValidatorIoHandlerTest extends MockObjectTestCase { 030 private IoHandler handler; 031 032 @Override 033 protected void setUp() throws Exception { 034 super.setUp(); 035 036 handler = new HaikuValidatorIoHandler(); 037 } 038 039 public void testValidHaiku() throws Exception { 040 Mock session = mock(IoSession.class); 041 session.expects(once()).method("write").with(eq("HAIKU!")); 042 IoSession sessionProxy = (IoSession) session.proxy(); 043 044 handler.messageReceived(sessionProxy, new Haiku( 045 "Oh, I drank too much.", "Why, oh why did I sign up", 046 "For an eight thirty?")); 047 } 048 049 public void testInvalidHaiku() throws Exception { 050 Mock session = mock(IoSession.class); 051 session.expects(once()).method("write").with( 052 eq("NOT A HAIKU: phrase 1, 'foo' had 1 syllables, not 5")); 053 IoSession sessionProxy = (IoSession) session.proxy(); 054 055 handler.messageReceived(sessionProxy, 056 new Haiku("foo", "a haiku", "poo")); 057 } 058}