Add sample js and android plugin

Summary:
The start of an example plugin.

My intention is for this to be a place that we keep up to date with the current best practice for doing things.

For example, with the introduction on persistedStateReducer, there are two ways to receive incoming messages, but only one of them works in the background. This should act as a guideline.

For this reason, don't hold back on reviewing it. I want it to be 👌

Reviewed By: priteshrnandgaonkar

Differential Revision: D10448592

fbshipit-source-id: d5fa978c14e47a7fa3c9a29d0929d5a6109267af
This commit is contained in:
John Knox
2018-10-19 09:42:00 -07:00
committed by Facebook Github Bot
parent 881d066369
commit 6cc7f60cde
8 changed files with 283 additions and 6 deletions

View File

@@ -0,0 +1,38 @@
/*
* 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;
@RunWith(RobolectricTestRunner.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()));
}
}