KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > data > AbstractMetaDataProviderTst


1 /*
2  * $Id: AbstractMetaDataProviderTst.java,v 1.2 2005/03/01 13:28:02 kleopatra Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7 package org.jdesktop.swing.data;
8
9 import junit.framework.TestCase;
10
11 /**
12  * Common TestCase which must be passed by MetaDataProvider
13  * implementations.
14  * For each implementation, subclass this and override the
15  * abstract methods.
16  *
17  * NOTE: the postfix "Tst" is _not_ a spelling error! It's there
18  * to hide this from the build (which includes and runs all tests
19  * with postfix "Test".
20  *
21  * @author Jeanette Winzenburg
22  */

23 public abstract class AbstractMetaDataProviderTst extends TestCase {
24     
25     protected MetaData[] defaultMetaData;
26
27     public void testEmptyProvider() {
28         MetaDataProvider provider = createEmptyMetaDataProvider();
29         assertNotNull("provider must not be null", provider);
30         assertEquals("fieldCount must be 0", 0, provider.getFieldCount());
31     }
32
33     public void testFilledProvider() {
34         MetaDataProvider provider = createFilledMetaDataProvider();
35         assertNotNull("provider must not be null", provider);
36         assertEquals("fieldCount must be ", defaultMetaData.length, provider.getFieldCount());
37         
38         
39     }
40
41     /**
42      * test that sequence of fieldnames is same as metaData.
43      *
44      */

45     public void testFieldSequence() {
46         MetaDataProvider provider = createFilledMetaDataProvider();
47         String JavaDoc[] fieldNames = provider.getFieldNames();
48         assertEquals("fieldCount must be same as metaData length", defaultMetaData.length, provider.getFieldCount());
49         for (int i = 0; i < fieldNames.length; i++) {
50             assertEquals("fieldname must equal metaData", defaultMetaData[i].getName(), fieldNames[i]);
51         }
52         
53     }
54     protected void setUp() throws Exception JavaDoc {
55         super.setUp();
56         defaultMetaData = createDefaultMetaData();
57     }
58     
59     protected MetaData[] createDefaultMetaData() {
60         MetaData[] metas = new MetaData[3];
61         metas[0] = new MetaData("firstName", String JavaDoc.class, "First Name");
62         metas[1] = new MetaData("second", Boolean JavaDoc.class, "Has Money");
63         metas[2] = new MetaData("amount", Number JavaDoc.class, "Total Funds");
64         return metas;
65     }
66
67     protected abstract MetaDataProvider createFilledMetaDataProvider();
68     
69     protected abstract MetaDataProvider createEmptyMetaDataProvider();
70 }
71
Popular Tags