KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > UtilTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.freeform;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collections JavaDoc;
25 import org.openide.filesystems.FileObject;
26 import org.openide.filesystems.FileUtil;
27
28 /**
29  * Test utility functions.
30  * @author Jesse Glick
31  */

32 public class UtilTest extends TestBase {
33
34     public UtilTest(String JavaDoc name) {
35         super(name);
36     }
37
38     private FileObject test1Xml;
39     private FileObject test2Xml;
40     private FileObject test3Xml;
41     private FileObject test5Xml;
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         test1Xml = FileUtil.toFileObject(new File JavaDoc(datadir, "test1.xml"));
46         assertNotNull("have test1.xml", test1Xml);
47         test2Xml = FileUtil.toFileObject(new File JavaDoc(datadir, "test2.xml"));
48         assertNotNull("have test2.xml", test2Xml);
49         test3Xml = FileUtil.toFileObject(new File JavaDoc(datadir, "test3.xml"));
50         assertNotNull("have test3.xml", test3Xml);
51         test5Xml = FileUtil.toFileObject(new File JavaDoc(datadir, "test5.xml"));
52         assertNotNull("have test5.xml", test5Xml);
53     }
54     
55     public void testGetAntScriptName() throws Exception JavaDoc {
56         assertEquals("correct name for test1.xml", "test1", Util.getAntScriptName(test1Xml));
57         assertEquals("no name for test2.xml", null, Util.getAntScriptName(test2Xml));
58         assertEquals("correct name for test3.xml", "test3", Util.getAntScriptName(test3Xml));
59         assertEquals("no name for test5.xml", null, Util.getAntScriptName(test5Xml));
60     }
61     
62     public void testGetAntScriptTargetNames() throws Exception JavaDoc {
63         assertEquals("correct targets for test1.xml",
64             Arrays.asList(new String JavaDoc[] {"another", "main", "other"}),
65             Util.getAntScriptTargetNames(test1Xml));
66         assertEquals("correct targets for test2.xml",
67             Collections.singletonList("sometarget"),
68             Util.getAntScriptTargetNames(test2Xml));
69         assertEquals("correct targets for test3.xml",
70             Arrays.asList(new String JavaDoc[] {"imported1", "imported2", "main"}),
71             Util.getAntScriptTargetNames(test3Xml));
72         assertEquals("no targets for test5.xml", null, Util.getAntScriptTargetNames(test5Xml));
73     }
74
75 }
76
Popular Tags