Summary: Add an ability to inspect errors reported through `ErrorReportingRunnable`.

Reviewed By: jknoxville

Differential Revision: D14640270

fbshipit-source-id: a5a79d647e20d5d46c85aac2a814c77abbc624b7
This commit is contained in:
Pascal Hartig
2019-03-27 10:06:26 -07:00
committed by Facebook Github Bot
parent 4d0b1d2fc3
commit d08a123ae4
3 changed files with 38 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ import java.util.Map;
public class FlipperConnectionMock implements FlipperConnection {
public final Map<String, FlipperReceiver> receivers = new HashMap<>();
public final Map<String, List<Object>> sent = new HashMap<>();
public final List<Throwable> errors = new ArrayList<>();
@Override
public void send(String method, FlipperObject params) {
@@ -47,7 +48,9 @@ public class FlipperConnectionMock implements FlipperConnection {
}
@Override
public void reportError(Throwable throwable) {}
public void reportError(Throwable throwable) {
errors.add(throwable);
}
@Override
public void receive(String method, FlipperReceiver receiver) {

View File

@@ -7,6 +7,7 @@
*/
package com.facebook.flipper.plugins.inspector;
import static com.facebook.flipper.plugins.inspector.ThrowableMessageMatcher.hasThrowableWithMessage;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,8 +32,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@@ -297,8 +298,7 @@ public class InspectorFlipperPluginTest {
Mockito.verify(decorView, Mockito.times(1)).removeView(Mockito.any(TouchOverlayView.class));
}
@Ignore("Will be resurrected with next diff in stack")
@Test(expected = RuntimeException.class)
@Test
public void testNullChildThrows() throws Exception {
final InspectorFlipperPlugin plugin =
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
@@ -309,7 +309,7 @@ public class InspectorFlipperPluginTest {
final TestNode root = new TestNode();
root.id = "test";
root.name = "test";
root.children = new ArrayList<>();
root.children = new ArrayList<>(1);
root.children.add(null);
mApplicationDescriptor.root = root;
@@ -317,6 +317,9 @@ public class InspectorFlipperPluginTest {
plugin.mGetNodes.onReceive(
new FlipperObject.Builder().put("ids", new FlipperArray.Builder().put("test")).build(),
responder);
assertThat(
connection.errors, CoreMatchers.hasItem(hasThrowableWithMessage("Unexpected null value")));
}
private class TestNode {

View File

@@ -0,0 +1,27 @@
package com.facebook.flipper.plugins.inspector;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
/** Match a throwable with a given message. */
class ThrowableMessageMatcher extends TypeSafeMatcher<Throwable> {
private final String mMessage;
public static ThrowableMessageMatcher hasThrowableWithMessage(String message) {
return new ThrowableMessageMatcher(message);
}
ThrowableMessageMatcher(String message) {
mMessage = message;
}
@Override
public void describeTo(Description description) {
description.appendText("a throwable with message ").appendText(mMessage);
}
@Override
protected boolean matchesSafely(Throwable item) {
return item.getMessage().equals(mMessage);
}
}