01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
19: package org.apache.tools.ant.types.selectors;
20:
21: import org.apache.tools.ant.BuildException;
22:
23: /**
24: * Tests Type Selectors.
25: *
26: */
27: public class TypeSelectorTest extends BaseSelectorTest {
28:
29: public TypeSelectorTest(String name) {
30: super (name);
31: }
32:
33: /**
34: * Factory method from base class. This is overriden in child
35: * classes to return a specific Selector class.
36: */
37: public BaseSelector getInstance() {
38: return new TypeSelector();
39: }
40:
41: /**
42: * Test the code that validates the selector.
43: */
44: public void testValidate() {
45: TypeSelector s = (TypeSelector) getInstance();
46: try {
47: s.isSelected(basedir, filenames[0], files[0]);
48: fail("TypeSelector did not check for required fields");
49: } catch (BuildException be1) {
50: assertEquals("The type attribute is required", be1
51: .getMessage());
52: }
53: }
54:
55: /**
56: * Tests to make sure that the selector is selecting files correctly.
57: */
58: public void testSelectionBehaviour() {
59: TypeSelector s;
60: String results;
61:
62: TypeSelector.FileType directory = new TypeSelector.FileType();
63: directory.setValue("dir");
64: TypeSelector.FileType file = new TypeSelector.FileType();
65: file.setValue("file");
66:
67: try {
68: makeBed();
69:
70: s = (TypeSelector) getInstance();
71: s.setType(directory);
72: results = selectionString(s);
73: assertEquals("TFFFFFFFFFFT", results);
74:
75: s = (TypeSelector) getInstance();
76: s.setType(file);
77: results = selectionString(s);
78: assertEquals("FTTTTTTTTTTF", results);
79:
80: } finally {
81: cleanupBed();
82: }
83:
84: }
85:
86: }
|