SyncFailedExceptionTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
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 18package tests.api.java.io; 19 20import dalvik.annotation.TestTargetClass; 21import dalvik.annotation.TestInfo; 22import dalvik.annotation.TestTarget; 23import dalvik.annotation.TestLevel; 24 25import java.io.File; 26import java.io.FileDescriptor; 27import java.io.FileOutputStream; 28import java.io.SyncFailedException; 29 30@TestTargetClass(SyncFailedException.class) 31public class SyncFailedExceptionTest extends junit.framework.TestCase { 32 33 /** 34 * @tests java.io.SyncFailedException#SyncFailedException(java.lang.String) 35 */ 36 @TestInfo( 37 level = TestLevel.COMPLETE, 38 purpose = "", 39 targets = { 40 @TestTarget( 41 methodName = "SyncFailedException", 42 methodArgs = {java.lang.String.class} 43 ) 44 }) 45 public void test_ConstructorLjava_lang_String() { 46 // Test for method java.io.SyncFailedException(java.lang.String) 47 File f = null; 48 try { 49 f = new File(System.getProperty("user.dir"), "synfail.tst"); 50 FileOutputStream fos = new FileOutputStream(f.getPath()); 51 FileDescriptor fd = fos.getFD(); 52 fos.close(); 53 fd.sync(); 54 } catch (SyncFailedException e) { 55 f.delete(); 56 return; 57 } catch (Exception e) { 58 fail("Exception during test : " + e.getMessage()); 59 } 60 fail("Failed to generate expected Exception"); 61 } 62 63 /** 64 * Sets up the fixture, for example, open a network connection. This method 65 * is called before a test is executed. 66 */ 67 protected void setUp() { 68 } 69 70 /** 71 * Tears down the fixture, for example, close a network connection. This 72 * method is called after a test is executed. 73 */ 74 protected void tearDown() { 75 } 76} 77