• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Guava Authors
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 com.google.common.io;
18 
19 import static com.google.common.io.FileBackedOutputStreamTest.write;
20 
21 import com.google.common.testing.GcFinalization;
22 import java.io.File;
23 
24 /**
25  * Android-incompatible tests for {@link FileBackedOutputStream}.
26  *
27  * @author Chris Nokleberg
28  */
29 @AndroidIncompatible // Finalization probably just doesn't happen fast enough?
30 public class FileBackedOutputStreamAndroidIncompatibleTest extends IoTestCase {
31 
testFinalizeDeletesFile()32   public void testFinalizeDeletesFile() throws Exception {
33     byte[] data = newPreFilledByteArray(100);
34     FileBackedOutputStream out = new FileBackedOutputStream(0, true);
35 
36     write(out, data, 0, 100, true);
37     final File file = out.getFile();
38     assertEquals(100, file.length());
39     assertTrue(file.exists());
40     out.close();
41 
42     // Make sure that finalize deletes the file
43     out = null;
44 
45     // times out and throws RuntimeException on failure
46     GcFinalization.awaitDone(
47         new GcFinalization.FinalizationPredicate() {
48           @Override
49           public boolean isDone() {
50             return !file.exists();
51           }
52         });
53   }
54 }
55