KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > event > StoreEventTest


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package javax.mail.event;
19 import javax.mail.Store;
20 import javax.mail.TestData;
21 import junit.framework.TestCase;
22 /**
23  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
24  */

25 public class StoreEventTest extends TestCase {
26     public StoreEventTest(String name) {
27         super(name);
28     }
29     public void testEvent() {
30         doEventTests(StoreEvent.ALERT);
31         doEventTests(StoreEvent.NOTICE);
32         try {
33             StoreEvent event = new StoreEvent(null, -12345, "Hello World");
34             fail(
35                 "Expected exception due to invalid type "
36                     + event.getMessageType());
37         } catch (IllegalArgumentException e) {
38         }
39     }
40     private void doEventTests(int type) {
41         Store source = TestData.getTestStore();
42         StoreEvent event = new StoreEvent(source, type, "Hello World");
43         assertEquals(source, event.getSource());
44         assertEquals("Hello World", event.getMessage());
45         assertEquals(type, event.getMessageType());
46         StoreListenerTest listener = new StoreListenerTest();
47         event.dispatch(listener);
48         assertEquals("Unexpcted method dispatched", type, listener.getState());
49     }
50     public static class StoreListenerTest implements StoreListener {
51         private int state = 0;
52         public void notification(StoreEvent event) {
53             if (state != 0) {
54                 fail("Recycled Listener");
55             }
56             state = event.getMessageType();
57         }
58         public int getState() {
59             return state;
60         }
61     }
62 }
63
Popular Tags