Home | History | Annotate | Download | only in file
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      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 libcore.java.nio.file;
     18 
     19 import junit.framework.TestCase;
     20 
     21 import java.io.IOException;
     22 import java.nio.file.AccessDeniedException;
     23 import java.nio.file.FileSystemException;
     24 import libcore.util.SerializationTester;
     25 
     26 public class AccessDeniedExceptionTest extends TestCase {
     27 
     28     public void test_constructor$String() {
     29         AccessDeniedException exception = new AccessDeniedException("file");
     30         assertEquals("file", exception.getFile());
     31         assertNull(exception.getOtherFile());
     32         assertNull(exception.getReason());
     33 
     34         assertTrue(exception instanceof FileSystemException);
     35     }
     36 
     37     public void test_constructor$String$String$String() {
     38         AccessDeniedException exception = new AccessDeniedException("file", "otherFile", "reason");
     39         assertEquals("file", exception.getFile());
     40         assertEquals("otherFile", exception.getOtherFile());
     41         assertEquals("reason", exception.getReason());
     42     }
     43 
     44     public void test_serialization() throws IOException, ClassNotFoundException {
     45         String hex = "aced0005737200236a6176612e6e696f2e66696c652e41636365737344656e6965644578"
     46                 + "63657074696f6e44993d6bf81c2721020000787200216a6176612e6e696f2e66696c652e46696c65"
     47                 + "53797374656d457863657074696f6ed598f27876d360fc0200024c000466696c657400124c6a6176"
     48                 + "612f6c616e672f537472696e673b4c00056f7468657271007e0002787200136a6176612e696f2e49"
     49                 + "4f457863657074696f6e6c8073646525f0ab020000787200136a6176612e6c616e672e4578636570"
     50                 + "74696f6ed0fd1f3e1a3b1cc4020000787200136a6176612e6c616e672e5468726f7761626c65d5c6"
     51                 + "35273977b8cb0300044c000563617573657400154c6a6176612f6c616e672f5468726f7761626c65"
     52                 + "3b4c000d64657461696c4d65737361676571007e00025b000a737461636b547261636574001e5b4c"
     53                 + "6a6176612f6c616e672f537461636b5472616365456c656d656e743b4c0014737570707265737365"
     54                 + "64457863657074696f6e737400104c6a6176612f7574696c2f4c6973743b787071007e0009740006"
     55                 + "726561736f6e7572001e5b4c6a6176612e6c616e672e537461636b5472616365456c656d656e743b"
     56                 + "02462a3c3cfd22390200007870000000097372001b6a6176612e6c616e672e537461636b54726163"
     57                 + "65456c656d656e746109c59a2636dd8502000449000a6c696e654e756d6265724c000e6465636c61"
     58                 + "72696e67436c61737371007e00024c000866696c654e616d6571007e00024c000a6d6574686f644e"
     59                 + "616d6571007e000278700000002674002f6c6962636f72652e6a6176612e6e696f2e66696c652e41"
     60                 + "636365737344656e696564457863657074696f6e5465737474001e41636365737344656e69656445"
     61                 + "7863657074696f6e546573742e6a617661740025746573745f636f6e7374727563746f7224537472"
     62                 + "696e6724537472696e6724537472696e677371007e000dfffffffe7400186a6176612e6c616e672e"
     63                 + "7265666c6563742e4d6574686f6474000b4d6574686f642e6a617661740006696e766f6b65737100"
     64                 + "7e000d000000f9740028766f6761722e7461726765742e6a756e69742e4a756e69743324566f6761"
     65                 + "724a556e69745465737474000b4a756e6974332e6a61766174000372756e7371007e000d00000063"
     66                 + "740020766f6761722e7461726765742e6a756e69742e4a556e697452756e6e657224317400104a55"
     67                 + "6e697452756e6e65722e6a61766174000463616c6c7371007e000d0000005c740020766f6761722e"
     68                 + "7461726765742e6a756e69742e4a556e697452756e6e657224317400104a556e697452756e6e6572"
     69                 + "2e6a61766174000463616c6c7371007e000d000000ed74001f6a6176612e7574696c2e636f6e6375"
     70                 + "7272656e742e4675747572655461736b74000f4675747572655461736b2e6a61766174000372756e"
     71                 + "7371007e000d0000046d7400276a6176612e7574696c2e636f6e63757272656e742e546872656164"
     72                 + "506f6f6c4578656375746f72740017546872656164506f6f6c4578656375746f722e6a6176617400"
     73                 + "0972756e576f726b65727371007e000d0000025f74002e6a6176612e7574696c2e636f6e63757272"
     74                 + "656e742e546872656164506f6f6c4578656375746f7224576f726b6572740017546872656164506f"
     75                 + "6f6c4578656375746f722e6a61766174000372756e7371007e000d000002f97400106a6176612e6c"
     76                 + "616e672e54687265616474000b5468726561642e6a61766174000372756e7372001f6a6176612e75"
     77                 + "74696c2e436f6c6c656374696f6e7324456d7074794c6973747ab817b43ca79ede02000078707874"
     78                 + "000466696c657400096f7468657246696c65";
     79         AccessDeniedException exception = (AccessDeniedException)
     80                 SerializationTester.deserializeHex(hex);
     81 
     82         String hex1 = SerializationTester.serializeHex(exception).toString();
     83         assertEquals(hex, hex1);
     84         assertEquals("file", exception.getFile());
     85         assertEquals("otherFile", exception.getOtherFile());
     86         assertEquals("reason", exception.getReason());
     87     }
     88 }
     89