Basic.java revision 893:f06f30b29f36
1/* 2 * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24/* @test 25 * @bug 4313887 26 * @summary Unit test for java.nio.file.FileStore 27 * @library .. 28 */ 29 30import java.nio.file.*; 31import java.nio.file.attribute.*; 32import java.io.IOException; 33import java.util.*; 34 35public class Basic { 36 37 public static void main(String[] args) throws IOException { 38 Path dir = TestUtil.createTemporaryDirectory(); 39 try { 40 doTests(dir); 41 } finally { 42 TestUtil.removeAll(dir); 43 } 44 } 45 46 static void assertTrue(boolean okay) { 47 if (!okay) 48 throw new RuntimeException("Assertion failed"); 49 } 50 51 static void doTests(Path dir) throws IOException { 52 /** 53 * Test: Directory should be on FileStore that is writable 54 */ 55 assertTrue(!dir.getFileStore().isReadOnly()); 56 57 /** 58 * Test: Two files should have the same FileStore 59 */ 60 FileStore store1 = dir.resolve("foo").createFile().getFileStore(); 61 FileStore store2 = dir.resolve("bar").createFile().getFileStore(); 62 assertTrue(store1.equals(store2)); 63 assertTrue(store2.equals(store1)); 64 assertTrue(store1.hashCode() == store2.hashCode()); 65 66 /** 67 * Test: File and FileStore attributes 68 */ 69 assertTrue(store1.supportsFileAttributeView("basic")); 70 71 /** 72 * Test: Enumerate all FileStores 73 */ 74 FileStore prev = null; 75 for (FileStore store: FileSystems.getDefault().getFileStores()) { 76 System.out.format("%s (name=%s type=%s)\n", store, store.name(), 77 store.type()); 78 79 // check space attributes 80 Attributes.readFileStoreSpaceAttributes(store); 81 82 // two distinct FileStores should not be equal 83 assertTrue(!store.equals(prev)); 84 prev = store; 85 } 86 } 87} 88