diff --git a/android/src/main/java/com/facebook/flipper/testing/FlipperConnectionMock.java b/android/src/main/java/com/facebook/flipper/testing/FlipperConnectionMock.java index 24fb3df5b..1d64e42d1 100644 --- a/android/src/main/java/com/facebook/flipper/testing/FlipperConnectionMock.java +++ b/android/src/main/java/com/facebook/flipper/testing/FlipperConnectionMock.java @@ -19,6 +19,7 @@ import java.util.Map; public class FlipperConnectionMock implements FlipperConnection { public final Map receivers = new HashMap<>(); public final Map> sent = new HashMap<>(); + public final List 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) { diff --git a/android/src/test/java/com/facebook/flipper/plugins/inspector/InspectorFlipperPluginTest.java b/android/src/test/java/com/facebook/flipper/plugins/inspector/InspectorFlipperPluginTest.java index f98da4192..c35c0be12 100644 --- a/android/src/test/java/com/facebook/flipper/plugins/inspector/InspectorFlipperPluginTest.java +++ b/android/src/test/java/com/facebook/flipper/plugins/inspector/InspectorFlipperPluginTest.java @@ -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 { diff --git a/android/src/test/java/com/facebook/flipper/plugins/inspector/ThrowableMessageMatcher.java b/android/src/test/java/com/facebook/flipper/plugins/inspector/ThrowableMessageMatcher.java new file mode 100644 index 000000000..974b76c31 --- /dev/null +++ b/android/src/test/java/com/facebook/flipper/plugins/inspector/ThrowableMessageMatcher.java @@ -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 { + 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); + } +}