1   /*
2    * Copyright 2002-2004 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.springframework.richclient.command;
17  
18  import org.easymock.EasyMock;
19  
20  import junit.framework.Assert;
21  import junit.framework.TestCase;
22  
23  
24  /**
25   * Provides unit tests for the {@link CommandRegistryEvent} class.
26   *
27   * @author Kevin Stembridge
28   * @since 0.3
29   *
30   */
31  public class CommandRegistryEventTests extends TestCase {
32  
33      /**
34       * Creates a new uninitialized {@code CommandRegistryEventTests}.
35       */
36      public CommandRegistryEventTests() {
37          super();
38      }
39  
40      /**
41       * Tests that the event object can be created and its properties correctly retrieved. 
42       */
43      public final void testAll() {
44          
45          AbstractCommand command = new AbstractCommand("noOpCommand") {
46              public void execute() {
47                  //do nothing
48              }
49          };
50          
51          CommandRegistry registry = (CommandRegistry) EasyMock.createMock(CommandRegistry.class);
52          
53          try {
54              new CommandRegistryEvent(null, command);
55              Assert.fail("Should have thrown an IllegalArgumentException for null registry");
56          } 
57          catch (IllegalArgumentException e) {
58              //test passes
59          }
60          
61          try {
62              new CommandRegistryEvent(registry, null);
63              Assert.fail("Should have thrown an IllegalArgumentException for null command");
64          }
65          catch (IllegalArgumentException e) {
66              //test passes
67          }
68  
69          CommandRegistryEvent event = new CommandRegistryEvent(registry, command);
70          
71          Assert.assertEquals(command, event.getCommand());
72          Assert.assertEquals(registry, event.getSource());
73          
74      }
75  
76  }