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

Commit 7db3ab2c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "EntropyMixerTest: convert to JUnit4"

parents 9b44b28d 4fa8ebb4
Loading
Loading
Loading
Loading
+20 −12
Original line number Original line Diff line number Diff line
@@ -17,11 +17,18 @@
package com.android.server;
package com.android.server;


import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


import android.content.Context;
import android.content.Context;
import android.test.AndroidTestCase;


import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;


import java.io.File;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Files;
@@ -30,25 +37,26 @@ import java.util.Arrays;
/**
/**
 * Tests for {@link com.android.server.EntropyMixer}
 * Tests for {@link com.android.server.EntropyMixer}
 */
 */
public class EntropyMixerTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class EntropyMixerTest {


    private static final int SEED_FILE_SIZE = EntropyMixer.SEED_FILE_SIZE;
    private static final int SEED_FILE_SIZE = EntropyMixer.SEED_FILE_SIZE;


    private File dir;
    private Context context;
    private File seedFile;
    private File seedFile;
    private File randomReadDevice;
    private File randomReadDevice;
    private File randomWriteDevice;
    private File randomWriteDevice;


    @Override
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        dir = getContext().getDir("test", Context.MODE_PRIVATE);
        context = InstrumentationRegistry.getTargetContext();
        seedFile = createTempFile(dir, "entropy.dat");
        seedFile = createTempFile("entropy.dat");
        randomReadDevice = createTempFile(dir, "urandomRead");
        randomReadDevice = createTempFile("urandomRead");
        randomWriteDevice = createTempFile(dir, "urandomWrite");
        randomWriteDevice = createTempFile("urandomWrite");
    }
    }


    private File createTempFile(File dir, String prefix) throws Exception {
    private File createTempFile(String prefix) throws Exception {
        File file = File.createTempFile(prefix, null, dir);
        File file = File.createTempFile(prefix, null);
        file.deleteOnExit();
        file.deleteOnExit();
        return file;
        return file;
    }
    }
@@ -69,7 +77,7 @@ public class EntropyMixerTest extends AndroidTestCase {


        // The constructor should have the side effect of writing to
        // The constructor should have the side effect of writing to
        // randomWriteDevice and creating seedFile.
        // randomWriteDevice and creating seedFile.
        new EntropyMixer(getContext(), seedFile, randomReadDevice, randomWriteDevice);
        new EntropyMixer(context, seedFile, randomReadDevice, randomWriteDevice);


        // Since there was no old seed file, the data that was written to
        // Since there was no old seed file, the data that was written to
        // randomWriteDevice should contain only device-specific information.
        // randomWriteDevice should contain only device-specific information.
@@ -90,7 +98,7 @@ public class EntropyMixerTest extends AndroidTestCase {


        // The constructor should have the side effect of writing to
        // The constructor should have the side effect of writing to
        // randomWriteDevice and updating seedFile.
        // randomWriteDevice and updating seedFile.
        new EntropyMixer(getContext(), seedFile, randomReadDevice, randomWriteDevice);
        new EntropyMixer(context, seedFile, randomReadDevice, randomWriteDevice);


        // The data that was written to randomWriteDevice should consist of the
        // The data that was written to randomWriteDevice should consist of the
        // previous seed followed by the device-specific information.
        // previous seed followed by the device-specific information.