001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.hivemind.Messages; 020 import org.apache.tapestry.test.Creator; 021 import org.testng.annotations.Test; 022 023 /** 024 * Tests support for several deprecated methods on {@link org.apache.tapestry.AbstractComponent} 025 * related to accessing localized messages. This test case may be removed in 4.1, when the 026 * corresponding methods are removed. 027 * 028 * @author Howard Lewis Ship 029 * @since 4.0 030 */ 031 @Test 032 public class TestComponentMessageAccess extends BaseComponentTestCase 033 { 034 private AbstractComponent newComponent(Messages messages) 035 { 036 Creator c = new Creator(); 037 038 return (AbstractComponent) c.newInstance(AbstractComponent.class, new Object[] 039 { "messages", messages }); 040 } 041 042 @Test 043 public void testGetMessage() 044 { 045 Messages m = newMock(Messages.class); 046 047 expect(m.getMessage("fred")).andReturn("flintstone"); 048 049 AbstractComponent ac = newComponent(m); 050 051 replay(); 052 053 assertEquals("flintstone", ac.getMessages().getMessage("fred")); 054 055 verify(); 056 } 057 058 @Test 059 public void testFormat() 060 { 061 Messages m = newMock(Messages.class); 062 063 expect(m.format("fred", "flintstone")).andReturn("Fred Flintstone"); 064 065 AbstractComponent ac = newComponent(m); 066 067 replay(); 068 069 assertEquals("Fred Flintstone", ac.getMessages().format("fred", "flintstone")); 070 071 verify(); 072 073 expect(m.format("fred", "wilma", "dino")).andReturn("flintstone family"); 074 075 replay(); 076 077 assertEquals("flintstone family", ac.getMessages().format("fred", "wilma", "dino")); 078 079 verify(); 080 081 expect(m.format("fred", "wilma", "dino", "pebbles")).andReturn("flintstone family 2"); 082 083 replay(); 084 085 assertEquals("flintstone family 2", ac.getMessages().format("fred", "wilma", "dino", "pebbles")); 086 087 verify(); 088 089 Object[] arguments = new String[] 090 { "flinstone" }; 091 092 expect(m.format("fred", arguments)).andReturn("flintstone family 3"); 093 094 replay(); 095 096 assertEquals("flintstone family 3", ac.getMessages().format("fred", arguments)); 097 098 verify(); 099 100 } 101 }