Debian Codegraph @

sourceTest/java/ch/systemsx/cisd/base/io/RandomAccessFileImplTests.java

raw
1 /*
2 * Copyright 2007 - 2018 ETH Zuerich, CISD and SIS.
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 package ch.systemsx.cisd.base.io;
18
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21
22 import org.testng.annotations.Test;
23
24 import ch.systemsx.cisd.base.BuildAndEnvironmentInfo;
25
26 /**
27 * Test cases for {@link RandomAccessFileImpl}.
28 *
29 * @author Bernd Rinn
30 */
31 public class RandomAccessFileImplTests extends IRandomAccessFileTests
32 {
33
34 @Override
35 protected IRandomAccessFile createRandomAccessFile(String name)
36 {
37 return new RandomAccessFileImpl(create(name), "rw");
38 }
39
40 @Override
41 protected IRandomAccessFile createRandomAccessFile(String name, byte[] content)
42 {
43 final IRandomAccessFile f = new RandomAccessFileImpl(create(name), "rw");
44 f.write(content);
45 f.seek(0L);
46 return f;
47 }
48
49 public static void main(String[] args) throws Throwable
50 {
51 System.out.println(BuildAndEnvironmentInfo.INSTANCE);
52 System.out.println("Test class: " + RandomAccessFileImplTests.class.getSimpleName());
53 System.out.println();
54 final RandomAccessFileImplTests test = new RandomAccessFileImplTests();
55 try
56 {
57 for (Method m : RandomAccessFileImplTests.class.getMethods())
58 {
59 final Test testAnnotation = m.getAnnotation(Test.class);
60 if (testAnnotation == null)
61 {
62 continue;
63 }
64 if (m.getParameterTypes().length == 0)
65 {
66 System.out.println("Running " + m.getName());
67 test.setUp();
68 try
69 {
70 m.invoke(test);
71 } catch (InvocationTargetException wrapperThrowable)
72 {
73 final Throwable th = wrapperThrowable.getCause();
74 boolean exceptionFound = false;
75 for (Class<?> expectedExClazz : testAnnotation.expectedExceptions())
76 {
77 if (expectedExClazz == th.getClass())
78 {
79 exceptionFound = true;
80 break;
81 }
82 }
83 if (exceptionFound == false)
84 {
85 throw th;
86 }
87 }
88 }
89 }
90 System.out.println("Tests OK!");
91 } finally
92 {
93 test.afterClass();
94 }
95 }
96
97 }