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

Commit 4fa66699 authored by Felipe Leme's avatar Felipe Leme
Browse files

Implemented AtomicFile.toString()

It shows the path of the base filename.

Test: atest FrameworksUtilTests:android.util.AtomicFileTest
Fixes: 203131233

Change-Id: Ib8d36610a4c34d210cc465ec8006d4df33ef638d
parent 7be92d03
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);