| 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 ByteBufferRandomAccessFileTests extends IRandomAccessFileTests |
| 32 |
{ |
| 33 |
|
| 34 |
@Override |
| 35 |
protected IRandomAccessFile createRandomAccessFile(String name) |
| 36 |
{ |
| 37 |
return new ByteBufferRandomAccessFile(4096); |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
protected IRandomAccessFile createRandomAccessFile(String name, byte[] content) |
| 42 |
{ |
| 43 |
return new ByteBufferRandomAccessFile(content); |
| 44 |
} |
| 45 |
|
| 46 |
public static void main(String[] args) throws Throwable |
| 47 |
{ |
| 48 |
System.out.println(BuildAndEnvironmentInfo.INSTANCE); |
| 49 |
System.out.println("Test class: " + ByteBufferRandomAccessFileTests.class.getSimpleName()); |
| 50 |
System.out.println(); |
| 51 |
final ByteBufferRandomAccessFileTests test = new ByteBufferRandomAccessFileTests(); |
| 52 |
try |
| 53 |
{ |
| 54 |
for (Method m : ByteBufferRandomAccessFileTests.class.getMethods()) |
| 55 |
{ |
| 56 |
final Test testAnnotation = m.getAnnotation(Test.class); |
| 57 |
if (testAnnotation == null) |
| 58 |
{ |
| 59 |
continue; |
| 60 |
} |
| 61 |
if (m.getParameterTypes().length == 0) |
| 62 |
{ |
| 63 |
System.out.println("Running " + m.getName()); |
| 64 |
test.setUp(); |
| 65 |
try |
| 66 |
{ |
| 67 |
m.invoke(test); |
| 68 |
} catch (InvocationTargetException wrapperThrowable) |
| 69 |
{ |
| 70 |
final Throwable th = wrapperThrowable.getCause(); |
| 71 |
boolean exceptionFound = false; |
| 72 |
for (Class<?> expectedExClazz : testAnnotation.expectedExceptions()) |
| 73 |
{ |
| 74 |
if (expectedExClazz == th.getClass()) |
| 75 |
{ |
| 76 |
exceptionFound = true; |
| 77 |
break; |
| 78 |
} |
| 79 |
} |
| 80 |
if (exceptionFound == false) |
| 81 |
{ |
| 82 |
throw th; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
System.out.println("Tests OK!"); |
| 88 |
} finally |
| 89 |
{ |
| 90 |
test.afterClass(); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
} |