Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5dae3ca9 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Implemented AtomicFile.toString()"

parents f6ca9038 4fa66699
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ android_test {
        "frameworks-base-testutils",
        "mockito-target-minus-junit4",
        "androidx.test.ext.junit",
        "truth-prebuilt",
    ],

    libs: [
+12 −0
Original line number Diff line number Diff line
@@ -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);