Skip to content

Commit

Permalink
Migrate MainThreadExecutorTest to instrumentation test; Remove Robole…
Browse files Browse the repository at this point in the history
…ctric dependency
  • Loading branch information
najmsheikh committed Aug 17, 2020
1 parent a5c6c76 commit 343377e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion button-merchant/build.gradle
Expand Up @@ -107,7 +107,6 @@ dependencies {
testImplementation "junit:junit:$junitVersion"
testImplementation "org.mockito:mockito-core:$mockitoVersion"
testImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
testImplementation "org.robolectric:robolectric:3.8"
testImplementation 'org.json:json:20171018'
androidTestImplementation "com.android.support.test:runner:$testRunnerVersion"
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion"
Expand Down
@@ -1,7 +1,7 @@
/*
* MainThreadExecutorTest.java
*
* Copyright (c) 2018 Button, Inc. (https://usebutton.com)
* Copyright (c) 2020 Button, Inc. (https://usebutton.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,35 +26,34 @@
package com.usebutton.merchant;

import android.os.Looper;
import android.support.test.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;

import java.util.concurrent.Executor;

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

@RunWith(RobolectricTestRunner.class)
public class MainThreadExecutorTest {

private Executor executor = new MainThreadExecutor();

@Test
public void executor_shouldExecute() throws Exception {
public void executor_shouldExecute() {
final boolean[] executed = { false };
final Looper[] looper = { null };

executor.execute(new Runnable() {
@Override
public void run() {
assertEquals(Looper.myLooper(), Looper.getMainLooper());
looper[0] = Looper.myLooper();
executed[0] = true;
}
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();

Robolectric.flushForegroundThreadScheduler();
assertEquals(Looper.getMainLooper(), looper[0]);
assertTrue(executed[0]);
}
}

0 comments on commit 343377e

Please sign in to comment.