Fix test
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:
committed by
Facebook Github Bot
parent
4d0b1d2fc3
commit
d08a123ae4
@@ -19,6 +19,7 @@ import java.util.Map;
|
|||||||
public class FlipperConnectionMock implements FlipperConnection {
|
public class FlipperConnectionMock implements FlipperConnection {
|
||||||
public final Map<String, FlipperReceiver> receivers = new HashMap<>();
|
public final Map<String, FlipperReceiver> receivers = new HashMap<>();
|
||||||
public final Map<String, List<Object>> sent = new HashMap<>();
|
public final Map<String, List<Object>> sent = new HashMap<>();
|
||||||
|
public final List<Throwable> errors = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(String method, FlipperObject params) {
|
public void send(String method, FlipperObject params) {
|
||||||
@@ -47,7 +48,9 @@ public class FlipperConnectionMock implements FlipperConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportError(Throwable throwable) {}
|
public void reportError(Throwable throwable) {
|
||||||
|
errors.add(throwable);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receive(String method, FlipperReceiver receiver) {
|
public void receive(String method, FlipperReceiver receiver) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.facebook.flipper.plugins.inspector;
|
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.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.hasItem;
|
import static org.hamcrest.CoreMatchers.hasItem;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
@@ -31,8 +32,8 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -297,8 +298,7 @@ public class InspectorFlipperPluginTest {
|
|||||||
Mockito.verify(decorView, Mockito.times(1)).removeView(Mockito.any(TouchOverlayView.class));
|
Mockito.verify(decorView, Mockito.times(1)).removeView(Mockito.any(TouchOverlayView.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Will be resurrected with next diff in stack")
|
@Test
|
||||||
@Test(expected = RuntimeException.class)
|
|
||||||
public void testNullChildThrows() throws Exception {
|
public void testNullChildThrows() throws Exception {
|
||||||
final InspectorFlipperPlugin plugin =
|
final InspectorFlipperPlugin plugin =
|
||||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||||
@@ -309,7 +309,7 @@ public class InspectorFlipperPluginTest {
|
|||||||
final TestNode root = new TestNode();
|
final TestNode root = new TestNode();
|
||||||
root.id = "test";
|
root.id = "test";
|
||||||
root.name = "test";
|
root.name = "test";
|
||||||
root.children = new ArrayList<>();
|
root.children = new ArrayList<>(1);
|
||||||
root.children.add(null);
|
root.children.add(null);
|
||||||
mApplicationDescriptor.root = root;
|
mApplicationDescriptor.root = root;
|
||||||
|
|
||||||
@@ -317,6 +317,9 @@ public class InspectorFlipperPluginTest {
|
|||||||
plugin.mGetNodes.onReceive(
|
plugin.mGetNodes.onReceive(
|
||||||
new FlipperObject.Builder().put("ids", new FlipperArray.Builder().put("test")).build(),
|
new FlipperObject.Builder().put("ids", new FlipperArray.Builder().put("test")).build(),
|
||||||
responder);
|
responder);
|
||||||
|
|
||||||
|
assertThat(
|
||||||
|
connection.errors, CoreMatchers.hasItem(hasThrowableWithMessage("Unexpected null value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestNode {
|
private class TestNode {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user