001 // Copyright 2004, 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.binding; 016 017 import org.apache.hivemind.Location; 018 import org.apache.hivemind.Messages; 019 import org.apache.tapestry.IComponent; 020 import org.apache.tapestry.coerce.ValueConverter; 021 import static org.easymock.EasyMock.expect; 022 import org.testng.annotations.Test; 023 024 /** 025 * Tests for {@link org.apache.tapestry.binding.MessageBinding}. 026 * 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class TestMessageBinding extends BindingTestCase 032 { 033 034 public void testCreate() 035 { 036 IComponent component = newMock(IComponent.class); 037 ValueConverter vc = newValueConverter(); 038 Location l = fabricateLocation(12); 039 040 replay(); 041 042 MessageBinding b = new MessageBinding("param", vc, l, component, "key"); 043 044 assertSame(component, b.getComponent()); 045 assertEquals("key", b.getKey()); 046 047 verify(); 048 } 049 050 public void testToString() 051 { 052 IComponent component = newComponent(); 053 ValueConverter vc = newValueConverter(); 054 Location l = fabricateLocation(12); 055 056 expect(component.getExtendedId()).andReturn("Foo/bar.baz"); 057 058 replay(); 059 060 MessageBinding b = new MessageBinding("param", vc, l, component, "key"); 061 062 assertEquals("MessageBinding[Foo/bar.baz key]", b.toString()); 063 064 verify(); 065 } 066 067 public void testGetObject() 068 { 069 Messages m = newMock(Messages.class); 070 IComponent component = newComponent(); 071 Location l = fabricateLocation(12); 072 073 ValueConverter vc = newValueConverter(); 074 075 expect(component.getMessages()).andReturn(m); 076 077 expect(m.getMessage("key")).andReturn("value"); 078 079 replay(); 080 MessageBinding b = new MessageBinding("param", vc, l, component, "key"); 081 082 assertEquals("value", b.getObject()); 083 084 verify(); 085 } 086 }