/** * Tests the absence of {@link UnsupportedFileOperation} annotations in all methods corresponding to * {@link #getSupportedOperations() supported operations}, and the absence thereof for unsupported operations. * * @throws Exception should not happen */ @Test public void testUnsupportedFileOperationAnnotations() throws Exception { List<FileOperation> supportedOps = Arrays.asList(getSupportedOperations()); Class<? extends AbstractFile> fileClass = tempFile.getClass(); Method m; for(FileOperation op: FileOperation.values()) { m = op.getCorrespondingMethod(fileClass); assert supportedOps.contains(op) == !fileClass.getMethod(m.getName(), m.getParameterTypes()).isAnnotationPresent(UnsupportedFileOperation.class) :"File operation "+op+" does not match annotation of method "+m.getName(); } }
/** * Ensures that the return value of {@link AbstractFile#isFileOperationSupported(FileOperation)} is consistent * with {@link #getSupportedOperations() supported operations}. * * @throws Exception should not happen */ @Test public void testSupportedFileOperations() throws Exception { List<FileOperation> supportedOps = Arrays.asList(getSupportedOperations()); AbstractFile tempFile = getTemporaryFile(); Class<? extends AbstractFile> fileClass = tempFile.getClass(); for(FileOperation op: FileOperation.values()) { boolean opSupported = supportedOps.contains(op); assert opSupported == tempFile.isFileOperationSupported(op); assert opSupported == AbstractFile.isFileOperationSupported(op, fileClass); } }