Merge "Implemented AtomicFile.toString()"

This commit is contained in:
Felipe Leme
2021-11-05 15:07:14 +00:00
committed by Android (Google) Code Review
3 changed files with 18 additions and 0 deletions

View File

@@ -330,6 +330,11 @@ public class AtomicFile {
}
}
@Override
public String toString() {
return "AtomicFile[" + mBaseName + "]";
}
private static void rename(File source, File target) {
// We used to delete the target file before rename, but that isn't atomic, and the rename()
// syscall should atomically replace the target file. However in the case where the target

View File

@@ -33,6 +33,7 @@ android_test {
"frameworks-base-testutils",
"mockito-target-minus-junit4",
"androidx.test.ext.junit",
"truth-prebuilt",
],
libs: [

View File

@@ -16,6 +16,8 @@
package android.util;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
@@ -257,6 +259,16 @@ public class AtomicFileTest {
}
}
@Test
public void testToString() throws Exception {
AtomicFile atomicFile = new AtomicFile(mBaseFile);
String toString = atomicFile.toString();
assertThat(toString).contains("AtomicFile");
assertThat(toString).contains(mBaseFile.getAbsolutePath());
}
private static void writeBytes(@NonNull File file, @NonNull byte[] bytes) throws IOException {
try (FileOutputStream outputStream = new FileOutputStream(file)) {
outputStream.write(bytes);