Move example plugin out of core
Summary: We should not ship this as part of our distribution. Just meant we had to bifurcate our unit tests which is a bit awkward, but it works now. Reviewed By: jknoxville Differential Revision: D15146980 fbshipit-source-id: 496b000630bbfcaa663cddacb00550e1499a1279
This commit is contained in:
committed by
Facebook Github Bot
parent
821408056f
commit
b7fff23700
@@ -23,6 +23,12 @@ android {
|
||||
main {
|
||||
manifest.srcFile './AndroidManifest.xml'
|
||||
}
|
||||
|
||||
test {
|
||||
java {
|
||||
exclude 'com/facebook/flipper/plugins/facebook/**'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
@@ -52,5 +58,11 @@ dependencies {
|
||||
androidTestImplementation deps.testCore
|
||||
androidTestImplementation deps.testRules
|
||||
|
||||
// Unit tests
|
||||
testImplementation deps.mockito
|
||||
testImplementation deps.robolectric
|
||||
testImplementation deps.hamcrest
|
||||
testImplementation deps.junit
|
||||
|
||||
implementation project(':android')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
package com.facebook.flipper.plugins.example;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.flipper.core.FlipperConnection;
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.core.FlipperPlugin;
|
||||
import com.facebook.flipper.core.FlipperReceiver;
|
||||
import com.facebook.flipper.core.FlipperResponder;
|
||||
|
||||
public class ExampleFlipperPlugin implements FlipperPlugin {
|
||||
|
||||
public static final String ID = "Example";
|
||||
|
||||
@Nullable private Activity mActivity;
|
||||
|
||||
@Nullable private FlipperConnection mConnection;
|
||||
|
||||
private int mNotificationsSent = 0;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/*
|
||||
* Activity to be used to display incoming messages
|
||||
*/
|
||||
public void setActivity(Activity activity) {
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnect(FlipperConnection connection) {
|
||||
mConnection = connection;
|
||||
connection.receive(
|
||||
"displayMessage",
|
||||
new FlipperReceiver() {
|
||||
@Override
|
||||
public void onReceive(final FlipperObject params, FlipperResponder responder) {
|
||||
if (mActivity != null) {
|
||||
mActivity.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mActivity, params.getString("message"), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
responder.success(new FlipperObject.Builder().put("greeting", "Hello").build());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void triggerNotification() {
|
||||
if (mConnection != null) {
|
||||
mConnection.send(
|
||||
"triggerNotification", new FlipperObject.Builder().put("id", mNotificationsSent).build());
|
||||
mNotificationsSent++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect() {
|
||||
mConnection = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runInBackground() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
package com.facebook.flipper.plugins.example;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.hasItem;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.testing.FlipperConnectionMock;
|
||||
import com.facebook.flipper.testing.FlipperResponderMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(application = TestApplication.class)
|
||||
public class ExampleFlipperPluginTest {
|
||||
|
||||
@Test
|
||||
public void greetingTest() throws Exception {
|
||||
final ExampleFlipperPlugin plugin = new ExampleFlipperPlugin();
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
|
||||
plugin.onConnect(connection);
|
||||
connection
|
||||
.receivers
|
||||
.get("displayMessage")
|
||||
.onReceive(new FlipperObject.Builder().put("message", "test").build(), responder);
|
||||
|
||||
assertThat(
|
||||
responder.successes, hasItem(new FlipperObject.Builder().put("greeting", "Hello").build()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
package com.facebook.flipper.plugins.example;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
public class TestApplication extends Application {}
|
||||
Reference in New Issue
Block a user