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 */ 16package org.mockftpserver.stub.command; 17 18import org.apache.log4j.Logger; 19import org.mockftpserver.core.command.*; 20import org.mockftpserver.core.command.AbstractCommandHandlerTestCase; 21import org.mockftpserver.core.util.AssertFailedException; 22 23/** 24 * Tests for the SystCommandHandler class 25 * 26 * @version $Revision$ - $Date$ 27 * 28 * @author Chris Mair 29 */ 30public final class SystCommandHandlerTest extends AbstractCommandHandlerTestCase { 31 32 private static final Logger LOG = Logger.getLogger(SystCommandHandlerTest.class); 33 34 private SystCommandHandler commandHandler; 35 36 /** 37 * Test the handleCommand() method 38 */ 39 public void testHandleCommand() throws Exception { 40 41 final String SYSTEM_NAME = "UNIX"; 42 commandHandler.setSystemName(SYSTEM_NAME); 43 44 session.sendReply(ReplyCodes.SYST_OK, formattedReplyTextFor(ReplyCodes.SYST_OK, "\"" + SYSTEM_NAME + "\"")); 45 replay(session); 46 47 final Command COMMAND = new Command(CommandNames.SYST, EMPTY); 48 49 commandHandler.handleCommand(COMMAND, session); 50 verify(session); 51 52 verifyNumberOfInvocations(commandHandler, 1); 53 verifyNoDataElements(commandHandler.getInvocation(0)); 54 } 55 56 /** 57 * Test the SetSystemName method, passing in a null 58 */ 59 public void testSetSystemName_Null() { 60 try { 61 commandHandler.setSystemName(null); 62 fail("Expected AssertFailedException"); 63 } 64 catch (AssertFailedException expected) { 65 LOG.info("Expected: " + expected); 66 } 67 } 68 69 /** 70 * Perform initialization before each test 71 * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp() 72 */ 73 protected void setUp() throws Exception { 74 super.setUp(); 75 commandHandler = new SystCommandHandler(); 76 commandHandler.setReplyTextBundle(replyTextBundle); 77 } 78 79} 80