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