001 /* 002 * $Id: BasicMessageTestCase.java 354761 2005-12-07 15:11:58Z niallp $ 003 * $Revision: 354761 $ 004 * $Date: 2005-12-07 15:11:58 +0000 (Wed, 07 Dec 2005) $ 005 * 006 * ==================================================================== 007 * 008 * Copyright 2003-2005 The Apache Software Foundation 009 * 010 * Licensed under the Apache License, Version 2.0 (the "License"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * 022 */ 023 024 package org.apache.commons.resources.impl; 025 026 import junit.framework.Test; 027 import junit.framework.TestCase; 028 import junit.framework.TestSuite; 029 030 /** 031 * Unit tests for the <code>org.apache.commons.resources.Message</code> class. 032 * <p> 033 * Orginally based on org.apache.http.action.TestActionMessage, Revision 1.2. 034 */ 035 public class BasicMessageTestCase extends TestCase { 036 037 protected BasicMessage amWithNoValue = null; 038 039 protected BasicMessage amWithOneValue = null; 040 041 protected BasicMessage amWithMultipleValues = null; 042 043 /** 044 * Defines the testcase name for JUnit. 045 * 046 * @param theName the testcase's name. 047 */ 048 public BasicMessageTestCase(String theName) { 049 super(theName); 050 } 051 052 /** 053 * Start the tests. 054 * 055 * @param theArgs the arguments. Not used 056 */ 057 public static void main(String[] theArgs) { 058 junit.awtui.TestRunner.main( 059 new String[] { BasicMessageTestCase.class.getName()}); 060 } 061 062 /** 063 * @return a test suite (<code>TestSuite</code>) that includes all methods 064 * starting with "test" 065 */ 066 public static Test suite() { 067 // All methods starting with "test" will be executed in the test suite. 068 return new TestSuite(BasicMessageTestCase.class); 069 } 070 071 public void setUp() { 072 amWithNoValue = new BasicMessage("amWithNoValue"); 073 amWithOneValue = 074 new BasicMessage("amWithOneValue", new String("stringValue")); 075 amWithMultipleValues = 076 new BasicMessage("amWithOneValue", 077 new String[]{"stringValue1", "stringValue2", "stringValue3"}); 078 } 079 080 public void tearDown() { 081 amWithNoValue = null; 082 } 083 084 public void testBasicMessageWithNoValue() { 085 086 087 assertTrue( 088 "testBasicMessageWithNoValue value is not null", 089 amWithNoValue.getValues() == null); 090 091 assertTrue( 092 "testBasicMessageWithNoValue key is not amWithNoValue", 093 amWithNoValue.getKey() == "amWithNoValue"); 094 095 amWithNoValue = new BasicMessage(); 096 097 assertNull( 098 "testBasicMessageWithNoValue value is not null", 099 amWithNoValue.getValues()); 100 101 } 102 103 public void testBasicMessageWithAStringValue() { 104 Object[] values = amWithOneValue.getValues(); 105 assertTrue( 106 "testBasicMessageWithAStringValue value is not null", 107 values != null); 108 109 assertTrue( 110 "testBasicMessageWithAStringValue value[0] is not the string stringValue", 111 values[0].equals("stringValue")); 112 113 assertTrue( 114 "testBasicMessageWithAStringValue key is not amWithOneValue", 115 amWithOneValue.getKey() == "amWithOneValue"); 116 117 assertEquals("Test toString", amWithOneValue.toString(), "amWithOneValue[stringValue]"); 118 119 assertEquals("Test toString() (multiple)", 120 amWithMultipleValues.toString(), "amWithOneValue[stringValue1, stringValue2, stringValue3]"); 121 122 } 123 }