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.core.command; 17 18 import org.slf4j.Logger; 19 import org.slf4j.LoggerFactory; 20 import org.mockftpserver.core.util.AssertFailedException; 21 import org.mockftpserver.test.AbstractTestCase; 22 23 import java.util.ListResourceBundle; 24 import java.util.ResourceBundle; 25 26 /** 27 * Tests for the ReplyTextBundleUtil class. 28 * 29 * @version $Revision$ - $Date$ 30 * 31 * @author Chris Mair 32 */ 33 public final class ReplyTextBundleUtilTest extends AbstractTestCase { 34 35 private static final Logger LOG = LoggerFactory.getLogger(ReplyTextBundleUtilTest.class); 36 37 private ResourceBundle resourceBundle1; 38 private ResourceBundle resourceBundle2; 39 40 /** 41 * Test the setReplyTextBundleIfAppropriate() method, when the CommandHandler implements 42 * the ResourceBundleAware interface, and the replyTextBundle has not yet been set. 43 */ 44 public void testSetReplyTextBundleIfAppropriate_ReplyTextBundleAware_NotSetYet() { 45 AbstractTrackingCommandHandler commandHandler = new StaticReplyCommandHandler(); 46 ReplyTextBundleUtil.setReplyTextBundleIfAppropriate(commandHandler, resourceBundle1); 47 assertSame(resourceBundle1, commandHandler.getReplyTextBundle()); 48 } 49 50 /** 51 * Test the setReplyTextBundleIfAppropriate() method, when the CommandHandler implements 52 * the ResourceBundleAware interface, and the replyTextBundle has already been set. 53 */ 54 public void testSetReplyTextBundleIfAppropriate_ReplyTextBundleAware_AlreadySet() { 55 AbstractTrackingCommandHandler commandHandler = new StaticReplyCommandHandler(); 56 commandHandler.setReplyTextBundle(resourceBundle2); 57 ReplyTextBundleUtil.setReplyTextBundleIfAppropriate(commandHandler, resourceBundle1); 58 assertSame(resourceBundle2, commandHandler.getReplyTextBundle()); 59 } 60 61 /** 62 * Test the setReplyTextBundleIfAppropriate() method, when the CommandHandler does not 63 * implement the ResourceBundleAware interface. 64 */ 65 public void testSetReplyTextBundleIfAppropriate_NotReplyTextBundleAware() { 66 CommandHandler commandHandler = (CommandHandler) createMock(CommandHandler.class); 67 replay(commandHandler); 68 ReplyTextBundleUtil.setReplyTextBundleIfAppropriate(commandHandler, resourceBundle1); 69 verify(commandHandler); // expect no method calls 70 } 71 72 /** 73 * Test the setReplyTextBundleIfAppropriate() method, when the CommandHandler is null. 74 */ 75 public void testSetReplyTextBundleIfAppropriate_NullCommandHandler() { 76 try { 77 ReplyTextBundleUtil.setReplyTextBundleIfAppropriate(null, resourceBundle1); 78 fail("Expected AssertFailedException"); 79 } 80 catch (AssertFailedException expected) { 81 LOG.info("Expected: " + expected); 82 } 83 } 84 85 /** 86 * @see org.mockftpserver.test.AbstractTestCase#setUp() 87 */ 88 protected void setUp() throws Exception { 89 super.setUp(); 90 91 resourceBundle1 = new ListResourceBundle() { 92 protected Object[][] getContents() { 93 return null; 94 } 95 }; 96 97 resourceBundle2 = new ListResourceBundle() { 98 protected Object[][] getContents() { 99 return new Object[][] { { "a", "b" } }; 100 } 101 }; 102 } 103 104 } 105