KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > selectors > TypeSelectorTest


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.types.selectors;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.Project;
22 import org.apache.tools.ant.BuildFileTest;
23 import org.apache.tools.ant.types.Parameter;
24 import org.apache.tools.ant.util.JavaEnvUtils;
25
26 import java.text.SimpleDateFormat JavaDoc;
27 import java.text.ParsePosition JavaDoc;
28 import java.util.Date JavaDoc;
29
30 import junit.framework.TestCase;
31 import junit.framework.AssertionFailedError;
32
33 /**
34  * Tests Type Selectors.
35  *
36  */

37 public class TypeSelectorTest extends BaseSelectorTest {
38
39     public TypeSelectorTest(String JavaDoc name) {
40         super(name);
41     }
42
43     /**
44      * Factory method from base class. This is overriden in child
45      * classes to return a specific Selector class.
46      */

47     public BaseSelector getInstance() {
48         return new TypeSelector();
49     }
50
51     /**
52      * Test the code that validates the selector.
53      */

54     public void testValidate() {
55         TypeSelector s = (TypeSelector)getInstance();
56         try {
57             s.isSelected(basedir,filenames[0],files[0]);
58             fail("TypeSelector did not check for required fields");
59         } catch (BuildException be1) {
60             assertEquals("The type attribute is required"
61                     , be1.getMessage());
62         }
63     }
64
65     /**
66      * Tests to make sure that the selector is selecting files correctly.
67      */

68     public void testSelectionBehaviour() {
69         TypeSelector s;
70         String JavaDoc results;
71
72         TypeSelector.FileType directory = new
73                 TypeSelector.FileType();
74         directory.setValue("dir");
75         TypeSelector.FileType file = new
76                 TypeSelector.FileType();
77         file.setValue("file");
78
79         try {
80             makeBed();
81
82             s = (TypeSelector)getInstance();
83             s.setType(directory);
84             results = selectionString(s);
85             assertEquals("TFFFFFFFFFFT", results);
86
87             s = (TypeSelector)getInstance();
88             s.setType(file);
89             results = selectionString(s);
90             assertEquals("FTTTTTTTTTTF", results);
91
92
93         }
94         finally {
95             cleanupBed();
96         }
97
98     }
99
100 }
101
Popular Tags