001 /* 002 * Copyright 2002-2004 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.richclient.command; 017 018 import org.easymock.EasyMock; 019 020 import junit.framework.Assert; 021 import junit.framework.TestCase; 022 023 024 /** 025 * Provides unit tests for the {@link CommandRegistryEvent} class. 026 * 027 * @author Kevin Stembridge 028 * @since 0.3 029 * 030 */ 031 public class CommandRegistryEventTests extends TestCase { 032 033 /** 034 * Creates a new uninitialized {@code CommandRegistryEventTests}. 035 */ 036 public CommandRegistryEventTests() { 037 super(); 038 } 039 040 /** 041 * Tests that the event object can be created and its properties correctly retrieved. 042 */ 043 public final void testAll() { 044 045 AbstractCommand command = new AbstractCommand("noOpCommand") { 046 public void execute() { 047 //do nothing 048 } 049 }; 050 051 CommandRegistry registry = (CommandRegistry) EasyMock.createMock(CommandRegistry.class); 052 053 try { 054 new CommandRegistryEvent(null, command); 055 Assert.fail("Should have thrown an IllegalArgumentException for null registry"); 056 } 057 catch (IllegalArgumentException e) { 058 //test passes 059 } 060 061 try { 062 new CommandRegistryEvent(registry, null); 063 Assert.fail("Should have thrown an IllegalArgumentException for null command"); 064 } 065 catch (IllegalArgumentException e) { 066 //test passes 067 } 068 069 CommandRegistryEvent event = new CommandRegistryEvent(registry, command); 070 071 Assert.assertEquals(command, event.getCommand()); 072 Assert.assertEquals(registry, event.getSource()); 073 074 } 075 076 }