001 /* 002 * Copyright 2002-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.binding.form.support; 017 018 import java.awt.Color; 019 import java.util.Locale; 020 021 import javax.swing.Icon; 022 023 import org.easymock.EasyMock; 024 import org.springframework.binding.form.FieldFace; 025 import org.springframework.context.support.MessageSourceAccessor; 026 import org.springframework.context.support.StaticMessageSource; 027 import org.springframework.richclient.image.IconSource; 028 import org.springframework.richclient.test.SpringRichTestCase; 029 import org.springframework.richclient.test.TestIcon; 030 031 /** 032 * Testcase for MessageSourceFieldFaceSource 033 * 034 * @author Peter De Bruycker 035 */ 036 public class MessageSourceFieldFaceSourceTests extends SpringRichTestCase { 037 038 public void testLoadFieldFace() { 039 Icon testIcon = new TestIcon(Color.RED); 040 041 MessageSourceFieldFaceSource fieldFaceSource = new MessageSourceFieldFaceSource(); 042 043 StaticMessageSource messageSource = new StaticMessageSource(); 044 messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption"); 045 messageSource.addMessage("context.field.description", Locale.getDefault(), "the description"); 046 messageSource.addMessage("context.field.label", Locale.getDefault(), "the label"); 047 messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName"); 048 fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource)); 049 050 IconSource mockIconSource = (IconSource) EasyMock.createMock(IconSource.class); 051 EasyMock.expect(mockIconSource.getIcon("iconName")).andReturn(testIcon); 052 EasyMock.replay(mockIconSource); 053 054 fieldFaceSource.setIconSource(mockIconSource); 055 056 FieldFace face = fieldFaceSource.loadFieldFace("field", "context"); 057 058 assertEquals("the caption", face.getCaption()); 059 assertEquals("the label", face.getDisplayName()); 060 assertEquals("the description", face.getDescription()); 061 062 assertEquals(testIcon, face.getIcon()); 063 064 EasyMock.verify(mockIconSource); 065 } 066 067 }