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: package org.apache.poi.hpsf.basic;
19:
20: import java.io.File;
21: import java.io.FileFilter;
22: import java.util.logging.Logger;
23:
24: /**
25: * <p>Processes a test method for all OLE2 files in the HPSF test data
26: * directory. Well, this class does not check whether a file is an OLE2 file but
27: * rather whether its name begins with "Test".</p>
28: *
29: * @author Rainer Klute <a
30: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
31: * @since 2006-02-11
32: * @version $Id: AllDataFilesTester.java 489730 2006-12-22 19:18:16Z bayard $
33: */
34: public class AllDataFilesTester {
35:
36: /**
37: * <p>Interface specifying how to run a test on a single file.</p>
38: *
39: * @author Rainer Klute <a
40: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
41: * @since 2006-02-11
42: * @version $Id: AllDataFilesTester.java 489730 2006-12-22 19:18:16Z bayard $
43: */
44: public interface TestTask {
45: /**
46: * <p>Executes a test on a single file.</p>
47: *
48: * @param file the file
49: * @throws Throwable if the method throws anything.
50: */
51: void runTest(File file) throws Throwable;
52: }
53:
54: /**
55: * <p>Tests the simplified custom properties.</p>
56: *
57: * @param task the task to execute
58: * @throws Throwable
59: */
60: public void runTests(final TestTask task) throws Throwable {
61: final String dataDirName = System
62: .getProperty("HPSF.testdata.path");
63: final File dataDir = new File(dataDirName);
64: final File[] docs = dataDir.listFiles(new FileFilter() {
65: public boolean accept(final File file) {
66: return file.isFile()
67: && file.getName().startsWith("Test");
68: }
69: });
70: for (int i = 0; i < docs.length; i++) {
71: final File doc = docs[i];
72: final Logger logger = Logger
73: .getLogger(getClass().getName());
74: logger.info("Processing file \" " + doc.toString() + "\".");
75:
76: /* Execute the test task. */
77: task.runTest(doc);
78: }
79: }
80:
81: }
|