View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      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  package org.apache.commons.io;
18  
19  import java.io.FileNotFoundException;
20  import java.io.IOException;
21  import java.nio.file.FileSystemNotFoundException;
22  import java.util.stream.Stream;
23  
24  import org.apache.commons.io.input.BrokenInputStream;
25  import org.apache.commons.io.input.BrokenReader;
26  import org.apache.commons.io.output.BrokenOutputStream;
27  import org.apache.commons.io.output.BrokenWriter;
28  
29  /**
30   * Factory for parameterized tests of {@link BrokenInputStream}, {@link BrokenReader}, {@link BrokenOutputStream}, and {@link BrokenWriter}.
31   */
32  public class BrokenTestFactories {
33  
34      /**
35       * A custom Error class.
36       */
37      public static final class CustomError extends Error {
38  
39          private static final long serialVersionUID = 1L;
40  
41      }
42  
43      /**
44       * A custom Exception class.
45       */
46      public static final class CustomException extends Exception {
47  
48          private static final long serialVersionUID = 1L;
49  
50      }
51  
52      /**
53       * A custom RuntimeException class.
54       */
55      public static final class CustomRuntimeException extends RuntimeException {
56  
57          private static final long serialVersionUID = 1L;
58  
59      }
60  
61      /**
62       * Creates a stream of all throwable types used in testing broken streams.
63       *
64       * @return a stream of all throwable types used in testing broken streams.
65       */
66      public static Stream<Class<? extends Throwable>> parameters() {
67          // @formatter:off
68          return Stream.of(
69              Throwable.class,                    // JRE Root class
70              Exception.class,                    // JRE Root Exception class
71              IOException.class,                  // JRE Root IOException class
72              FileNotFoundException.class,        // JRE IOException subclass
73              RuntimeException.class,             // JRE Root RuntimeException
74              FileSystemNotFoundException.class,  // JRE RuntimeException subclass in NIO
75              IllegalArgumentException.class,     // JRE RuntimeException subclass
76              IllegalStateException.class,        // JRE RuntimeException subclass
77              Error.class,                        // JRE Error root class
78              ExceptionInInitializerError.class,  // JRE Error subclass
79              CustomException.class,              // Custom Exception subclass
80              CustomRuntimeException.class,       // Custom RuntimeException subclass
81              CustomError.class                   // Custom Error subclass
82          );
83          // @formatter:on
84      }
85  }