OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014, the Dart project authors. |
| 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. |
| 13 */ |
| 14 package com.google.dart.engine.internal.index.file; |
| 15 |
| 16 import com.google.common.io.Files; |
| 17 import com.google.dart.engine.utilities.io.FileUtilities2; |
| 18 |
| 19 import junit.framework.TestCase; |
| 20 |
| 21 import java.io.File; |
| 22 import java.io.InputStream; |
| 23 import java.io.OutputStream; |
| 24 |
| 25 public class SeparateFileManagerTest extends TestCase { |
| 26 private File tempDir; |
| 27 private SeparateFileManager fileManager; |
| 28 |
| 29 public void test_clear() throws Exception { |
| 30 String name = "42.index"; |
| 31 // create a file |
| 32 fileManager.openOutputStream(name).close(); |
| 33 // check that that file exists |
| 34 assertTrue(new File(tempDir, name).isFile()); |
| 35 // clear |
| 36 fileManager.clear(); |
| 37 assertFalse(new File(tempDir, name).isFile()); |
| 38 } |
| 39 |
| 40 public void test_outputInput() throws Exception { |
| 41 String name = "42.index"; |
| 42 // create a file |
| 43 { |
| 44 OutputStream stream = fileManager.openOutputStream(name); |
| 45 assertNotNull(stream); |
| 46 try { |
| 47 stream.write(0x01); |
| 48 stream.write(0x02); |
| 49 stream.write(0x03); |
| 50 stream.write(0x04); |
| 51 } finally { |
| 52 stream.close(); |
| 53 } |
| 54 } |
| 55 // check that that file exists |
| 56 assertTrue(new File(tempDir, name).isFile()); |
| 57 // get InputStream |
| 58 { |
| 59 InputStream stream = fileManager.openInputStream(name); |
| 60 assertNotNull(stream); |
| 61 try { |
| 62 assertEquals(0x01, stream.read()); |
| 63 assertEquals(0x02, stream.read()); |
| 64 assertEquals(0x03, stream.read()); |
| 65 assertEquals(0x04, stream.read()); |
| 66 } finally { |
| 67 stream.close(); |
| 68 } |
| 69 } |
| 70 // delete |
| 71 fileManager.delete(name); |
| 72 // no InputStream anymore |
| 73 assertNull(fileManager.openInputStream(name)); |
| 74 } |
| 75 |
| 76 @Override |
| 77 protected void setUp() throws Exception { |
| 78 super.setUp(); |
| 79 tempDir = Files.createTempDir(); |
| 80 fileManager = new SeparateFileManager(tempDir); |
| 81 } |
| 82 |
| 83 @Override |
| 84 protected void tearDown() throws Exception { |
| 85 FileUtilities2.deleteDirectory(tempDir); |
| 86 super.tearDown(); |
| 87 } |
| 88 } |
OLD | NEW |