Home | History | Annotate | Download | only in command
      1 /*
      2  * Copyright 2007 the original author or authors.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package org.mockftpserver.stub.command;
     17 
     18 import org.mockftpserver.core.command.AbstractCommandHandlerTestCase;
     19 import org.mockftpserver.core.command.Command;
     20 import org.mockftpserver.core.command.CommandNames;
     21 import org.mockftpserver.core.command.ReplyCodes;
     22 
     23 /**
     24  * Tests for the HelpCommandHandler class
     25  *
     26  * @version $Revision$ - $Date$
     27  *
     28  * @author Chris Mair
     29  */
     30 public final class HelpCommandHandlerTest extends AbstractCommandHandlerTestCase {
     31 
     32     private HelpCommandHandler commandHandler;
     33 
     34     /**
     35      * Test the handleCommand() method
     36      */
     37     public void testHandleCommand() throws Exception {
     38 
     39         final String RESPONSE_DATA = "help for ABC...";
     40         commandHandler.setHelpMessage(RESPONSE_DATA);
     41 
     42         session.sendReply(ReplyCodes.HELP_OK, formattedReplyTextFor(ReplyCodes.HELP_OK, RESPONSE_DATA));
     43         session.sendReply(ReplyCodes.HELP_OK, formattedReplyTextFor(ReplyCodes.HELP_OK, RESPONSE_DATA));
     44         replay(session);
     45 
     46         final Command COMMAND1 = new Command(CommandNames.HELP, EMPTY);
     47         final Command COMMAND2 = new Command(CommandNames.HELP, array("abc"));
     48 
     49         commandHandler.handleCommand(COMMAND1, session);
     50         commandHandler.handleCommand(COMMAND2, session);
     51         verify(session);
     52 
     53         verifyNumberOfInvocations(commandHandler, 2);
     54         verifyOneDataElement(commandHandler.getInvocation(0), HelpCommandHandler.COMMAND_NAME_KEY, null);
     55         verifyOneDataElement(commandHandler.getInvocation(1), HelpCommandHandler.COMMAND_NAME_KEY, "abc");
     56     }
     57 
     58     /**
     59      * Perform initialization before each test
     60      *
     61      * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
     62      */
     63     protected void setUp() throws Exception {
     64         super.setUp();
     65         commandHandler = new HelpCommandHandler();
     66         commandHandler.setReplyTextBundle(replyTextBundle);
     67     }
     68 
     69 }
     70