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

Commit cbf09319 authored by William Escande's avatar William Escande
Browse files

Reformat java file in android/app/tests

Bug: 311772251
Flag: Exempt refactor
Test: None
Change-Id: I9d280c4e5ad8c7362f6dff440b27180ee0e230b1
parent 45feb605
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -25,10 +25,7 @@ import org.junit.runner.RunWith;
import java.io.File;
import java.io.IOException;

/**
 * Test Bluetooth's ability to write to the different directories that it
 * is supposed to own
 */
/** Test Bluetooth's ability to write to the different directories that it is supposed to own */
@MediumTest
@RunWith(AndroidJUnit4.class)
public class FileSystemWriteTest {
+8 −4
Original line number Diff line number Diff line
@@ -40,8 +40,10 @@ public class ObexAppParametersTest {
    public void constructorWithByteArrays_withOneInvalidElement() {
        final int length = 4;

        byte[] byteArray = new byte[] {KEY, length, 0x12, 0x34, 0x56, 0x78,
                0x66}; // Last one is invalid. It will be filtered out.
        byte[] byteArray =
                new byte[] {
                    KEY, length, 0x12, 0x34, 0x56, 0x78, 0x66
                }; // Last one is invalid. It will be filtered out.

        ObexAppParameters params = new ObexAppParameters(byteArray);
        assertThat(params.exists(KEY)).isTrue();
@@ -53,8 +55,10 @@ public class ObexAppParametersTest {
    @Test
    public void constructorWithByteArrays_withTwoInvalidElements() {
        final int length = 4;
        byte[] byteArray = new byte[] {KEY, length, 0x12, 0x34, 0x56, 0x78,
                0x66, 0x77}; // Last two are invalid. It will be filtered out.
        byte[] byteArray =
                new byte[] {
                    KEY, length, 0x12, 0x34, 0x56, 0x78, 0x66, 0x77
                }; // Last two are invalid. It will be filtered out.

        ObexAppParameters params = new ObexAppParameters(byteArray);
        assertThat(params.exists(KEY)).isTrue();
+3 −7
Original line number Diff line number Diff line
@@ -25,9 +25,7 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Test for SignedLongLong.java
 */
/** Test for SignedLongLong.java */
@SmallTest
@RunWith(AndroidJUnit4.class)
public class SignedLongLongTest {
@@ -125,15 +123,13 @@ public class SignedLongLongTest {
    public void fromString_whenLengthIsNotGreaterThan16() throws Exception {
        String strValue = "1";

        assertThat(SignedLongLong.fromString(strValue))
                .isEqualTo(new SignedLongLong(1, 0));
        assertThat(SignedLongLong.fromString(strValue)).isEqualTo(new SignedLongLong(1, 0));
    }

    @Test
    public void fromString_whenLengthIsGreaterThan16() throws Exception {
        String strValue = "B0000000000000002";

        assertThat(SignedLongLong.fromString(strValue))
                .isEqualTo(new SignedLongLong(2, 11));
        assertThat(SignedLongLong.fromString(strValue)).isEqualTo(new SignedLongLong(2, 11));
    }
}
+61 −53
Original line number Diff line number Diff line
@@ -54,9 +54,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * A set of methods useful in Bluetooth instrumentation tests
 */
/** A set of methods useful in Bluetooth instrumentation tests */
public class TestUtils {
    private static final int SERVICE_TOGGLE_TIMEOUT_MS = 1000; // 1s

@@ -71,13 +69,14 @@ public class TestUtils {
     * @param fieldName field name to be replaced
     * @param obj instance of type c whose fieldName is to be replaced, null for static fields
     * @param newValue object used to replace fieldName
     * @return the old value of fieldName that got replaced, caller is responsible for restoring
     * it back to obj
     * @return the old value of fieldName that got replaced, caller is responsible for restoring it
     *     back to obj
     * @throws NoSuchFieldException when fieldName is not found in type c
     * @throws IllegalAccessException when fieldName cannot be accessed in type c
     */
    public static Object replaceField(final Class c, final String fieldName, final Object obj,
            final Object newValue) throws NoSuchFieldException, IllegalAccessException {
    public static Object replaceField(
            final Class c, final String fieldName, final Object obj, final Object newValue)
            throws NoSuchFieldException, IllegalAccessException {
        Field field = c.getDeclaredField(fieldName);
        field.setAccessible(true);

@@ -93,8 +92,10 @@ public class TestUtils {
     *     mocked or spied
     */
    public static void setAdapterService(AdapterService adapterService) {
        Assert.assertNull("AdapterService.getAdapterService() must be null before setting another"
                + " AdapterService", AdapterService.getAdapterService());
        Assert.assertNull(
                "AdapterService.getAdapterService() must be null before setting another"
                        + " AdapterService",
                AdapterService.getAdapterService());
        Assert.assertNotNull("Adapter service should not be null", adapterService);
        // We cannot mock AdapterService.getAdapterService() with Mockito.
        // Hence we need to set AdapterService.sAdapterService field.
@@ -108,8 +109,10 @@ public class TestUtils {
     *     TestUtils#setAdapterService(AdapterService)}
     */
    public static void clearAdapterService(AdapterService adapterService) {
        Assert.assertSame("AdapterService.getAdapterService() must return the same object as the"
                        + " supplied adapterService in this method", adapterService,
        Assert.assertSame(
                "AdapterService.getAdapterService() must return the same object as the"
                        + " supplied adapterService in this method",
                adapterService,
                AdapterService.getAdapterService());
        Assert.assertNotNull("Adapter service should not be null", adapterService);
        AdapterService.clearAdapterService(adapterService);
@@ -148,11 +151,13 @@ public class TestUtils {

    public static Resources getTestApplicationResources(Context context) {
        try {
            return context.getPackageManager().getResourcesForApplication(
                    "com.android.bluetooth.tests");
            return context.getPackageManager()
                    .getResourcesForApplication("com.android.bluetooth.tests");
        } catch (PackageManager.NameNotFoundException e) {
            assertWithMessage("Setup Failure: Unable to get test application resources"
                    + e.toString()).fail();
            assertWithMessage(
                            "Setup Failure: Unable to get test application resources"
                                    + e.toString())
                    .fail();
            return null;
        }
    }
@@ -178,8 +183,7 @@ public class TestUtils {
    /**
     * Wait and verify that no intent has been received.
     *
     * @param timeoutMs the time (in milliseconds) to wait and verify no intent
     *                  has been received
     * @param timeoutMs the time (in milliseconds) to wait and verify no intent has been received
     * @param queue the queue for the intent
     * @return the received intent. Should be null under normal circumstances
     */
@@ -200,7 +204,9 @@ public class TestUtils {
     * @param looper looper of interest
     */
    public static void waitForLooperToFinishScheduledTask(Looper looper) {
        runOnLooperSync(looper, () -> {
        runOnLooperSync(
                looper,
                () -> {
                    // do nothing, just need to make sure looper finishes current task
                });
    }
@@ -263,19 +269,18 @@ public class TestUtils {
    }

    /**
     * Run synchronously a runnable action on a looper.
     * The method will return after the action has been execution to completion.
     * Run synchronously a runnable action on a looper. The method will return after the action has
     * been execution to completion.
     *
     * <p>Example:
     *
     * Example:
     * <pre>
     * {@code
     * <pre>{@code
     * TestUtils.runOnMainSync(new Runnable() {
     *       public void run() {
     *           Assert.assertTrue(mA2dpService.stop());
     *       }
     *   });
     * }
     * </pre>
     * }</pre>
     *
     * @param looper the looper used to run the action
     * @param action the action to run
@@ -295,10 +300,8 @@ public class TestUtils {
    /**
     * Read Bluetooth adapter configuration from the filesystem
     *
     * @return A {@link HashMap} of Bluetooth configs in the format:
     * section -> key1 -> value1
     * -> key2 -> value2
     * Assume no empty section name, no duplicate keys in the same section
     * @return A {@link HashMap} of Bluetooth configs in the format: section -> key1 -> value1 ->
     *     key2 -> value2 Assume no empty section name, no duplicate keys in the same section
     */
    public static HashMap<String, HashMap<String, String>> readAdapterConfig() {
        HashMap<String, HashMap<String, String>> adapterConfig = new HashMap<>();
@@ -319,7 +322,10 @@ public class TestUtils {
                    adapterConfig.put(section, new HashMap<>());
                } else {
                    String[] keyValue = line.split("=");
                    adapterConfig.get(section).put(keyValue[0].trim(),
                    adapterConfig
                            .get(section)
                            .put(
                                    keyValue[0].trim(),
                                    keyValue.length == 1 ? "" : keyValue[1].trim());
                }
            }
@@ -336,14 +342,17 @@ public class TestUtils {
     * @return intent with the appropriate component & action set.
     */
    public static Intent prepareIntentToStartBluetoothBrowserMediaService() {
        final Intent intent = new Intent(InstrumentationRegistry.getTargetContext(),
        final Intent intent =
                new Intent(
                        InstrumentationRegistry.getTargetContext(),
                        BluetoothMediaBrowserService.class);
        intent.setAction(MediaBrowserService.SERVICE_INTERFACE);
        return intent;
    }

    public static void setUpUiTest() throws Exception {
        final UiDevice device = UiDevice.getInstance(
        final UiDevice device =
                UiDevice.getInstance(
                        androidx.test.platform.app.InstrumentationRegistry.getInstrumentation());
        // Disable animation
        device.executeShellCommand("settings put global window_animation_scale 0.0");
@@ -364,7 +373,8 @@ public class TestUtils {
    }

    public static void tearDownUiTest() throws Exception {
        final UiDevice device = UiDevice.getInstance(
        final UiDevice device =
                UiDevice.getInstance(
                        androidx.test.platform.app.InstrumentationRegistry.getInstrumentation());
        device.executeShellCommand("wm dismiss-keyguard");

@@ -374,8 +384,8 @@ public class TestUtils {
        device.executeShellCommand("settings put global animator_duration_scale 1.0");

        // restore screen_off_timeout
        device.executeShellCommand("settings put system screen_off_timeout "
                + sSystemScreenOffTimeout);
        device.executeShellCommand(
                "settings put system screen_off_timeout " + sSystemScreenOffTimeout);
    }

    public static class RetryTestRule implements TestRule {
@@ -420,9 +430,7 @@ public class TestUtils {
        }
    }

    /**
     * Helper class used to run synchronously a runnable action on a looper.
     */
    /** Helper class used to run synchronously a runnable action on a looper. */
    private static final class SyncRunnable implements Runnable {
        private final Runnable mTarget;
        private volatile boolean mComplete = false;
+6 −9
Original line number Diff line number Diff line
@@ -50,9 +50,7 @@ import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 * Test for Utils.java
 */
/** Test for Utils.java */
@SmallTest
@RunWith(AndroidJUnit4.class)
public class UtilsTest {
@@ -72,9 +70,9 @@ public class UtilsTest {

    @Test
    public void uuidsToByteArray() {
        ParcelUuid[] uuids = new ParcelUuid[] {
                new ParcelUuid(new UUID(10, 20)),
                new ParcelUuid(new UUID(30, 40))
        ParcelUuid[] uuids =
                new ParcelUuid[] {
                    new ParcelUuid(new UUID(10, 20)), new ParcelUuid(new UUID(30, 40))
                };
        ByteBuffer converter = ByteBuffer.allocate(uuids.length * 16);
        converter.order(ByteOrder.BIG_ENDIAN);
@@ -211,8 +209,7 @@ public class UtilsTest {
                .isEqualTo("STATE_TURNING_ON");
        assertThat(Utils.debugGetAdapterStateString(BluetoothAdapter.STATE_TURNING_OFF))
                .isEqualTo("STATE_TURNING_OFF");
        assertThat(Utils.debugGetAdapterStateString(-124))
                .isEqualTo("UNKNOWN");
        assertThat(Utils.debugGetAdapterStateString(-124)).isEqualTo("UNKNOWN");
    }

    @Test
Loading