mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Format Java code in xplat/js/react-native-github
Summary: This diff formats the Java class files inside xplat/js/react-native-github. Since google-java-format was enabled in D16071401 we want to codemode the existing code so that users don't have to deal with formatter lint noise at diff-time. ```arc f --paths-cmd 'hg files -I "**/*.java"'``` drop-conflicts Reviewed By: cpojer Differential Revision: D16071725 fbshipit-source-id: fc6e3852e45742c109f0c5ac4065d64201c74204
This commit is contained in:
committed by
Facebook Github Bot
parent
61e95e5cbf
commit
6c0f73b322
@@ -1,16 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.common.logging;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class FakeLoggingDelegate implements LoggingDelegate {
|
||||
@@ -21,11 +19,7 @@ public final class FakeLoggingDelegate implements LoggingDelegate {
|
||||
public final String msg;
|
||||
public final @Nullable Throwable tr;
|
||||
|
||||
private LogLine(
|
||||
int priority,
|
||||
String tag,
|
||||
String msg,
|
||||
@Nullable Throwable tr) {
|
||||
private LogLine(int priority, String tag, String msg, @Nullable Throwable tr) {
|
||||
|
||||
this.priority = priority;
|
||||
this.tag = tag;
|
||||
@@ -34,35 +28,30 @@ public final class FakeLoggingDelegate implements LoggingDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public static final int ASSERT = FLog.ASSERT;
|
||||
public static final int DEBUG = FLog.DEBUG;
|
||||
public static final int ERROR = FLog.ERROR;
|
||||
public static final int INFO = FLog.INFO;
|
||||
public static final int ASSERT = FLog.ASSERT;
|
||||
public static final int DEBUG = FLog.DEBUG;
|
||||
public static final int ERROR = FLog.ERROR;
|
||||
public static final int INFO = FLog.INFO;
|
||||
public static final int VERBOSE = FLog.VERBOSE;
|
||||
public static final int WARN = FLog.WARN;
|
||||
public static final int WARN = FLog.WARN;
|
||||
|
||||
/**
|
||||
* There is no log level for Terrible Failures (we emit them at the Error
|
||||
* Log-level), but to test that WTF errors are being logged, we are making up
|
||||
* a new log level here, guaranteed to be larger than any of the other log
|
||||
* levels.
|
||||
* There is no log level for Terrible Failures (we emit them at the Error Log-level), but to test
|
||||
* that WTF errors are being logged, we are making up a new log level here, guaranteed to be
|
||||
* larger than any of the other log levels.
|
||||
*/
|
||||
public static final int WTF =
|
||||
1 + Collections.max(Arrays.asList(ASSERT, DEBUG, ERROR, INFO, VERBOSE, WARN));
|
||||
1 + Collections.max(Arrays.asList(ASSERT, DEBUG, ERROR, INFO, VERBOSE, WARN));
|
||||
|
||||
private int mMinLogLevel = FLog.VERBOSE;
|
||||
private final ArrayList<LogLine> mLogs = new ArrayList<>();
|
||||
|
||||
/** Test Harness */
|
||||
|
||||
private static boolean matchLogQuery(
|
||||
int priority,
|
||||
String tag,
|
||||
@Nullable String throwMsg,
|
||||
LogLine line) {
|
||||
int priority, String tag, @Nullable String throwMsg, LogLine line) {
|
||||
return priority == line.priority
|
||||
&& tag.equals(line.tag)
|
||||
&& (throwMsg == null || throwMsg.equals(line.tr.getMessage()));
|
||||
&& tag.equals(line.tag)
|
||||
&& (throwMsg == null || throwMsg.equals(line.tr.getMessage()));
|
||||
}
|
||||
|
||||
public boolean logContains(int priority, String tag, String throwMsg) {
|
||||
@@ -76,7 +65,6 @@ public final class FakeLoggingDelegate implements LoggingDelegate {
|
||||
}
|
||||
|
||||
/** LoggingDelegate API */
|
||||
|
||||
public int getMinimumLoggingLevel() {
|
||||
return mMinLogLevel;
|
||||
}
|
||||
|
||||
@@ -1,44 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class CompositeReactPackageTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Mock ReactPackage packageNo1;
|
||||
@Mock ReactPackage packageNo2;
|
||||
@@ -99,11 +93,11 @@ public class CompositeReactPackageTest {
|
||||
NativeModule moduleNo4 = mock(NativeModule.class);
|
||||
when(moduleNo4.getName()).thenReturn("ModuleNo4");
|
||||
|
||||
when(packageNo1.createNativeModules(reactContext)).thenReturn(
|
||||
Arrays.asList(new NativeModule[]{moduleNo1, moduleNo2}));
|
||||
when(packageNo1.createNativeModules(reactContext))
|
||||
.thenReturn(Arrays.asList(new NativeModule[] {moduleNo1, moduleNo2}));
|
||||
|
||||
when(packageNo2.createNativeModules(reactContext)).thenReturn(
|
||||
Arrays.asList(new NativeModule[]{moduleNo3, moduleNo4}));
|
||||
when(packageNo2.createNativeModules(reactContext))
|
||||
.thenReturn(Arrays.asList(new NativeModule[] {moduleNo3, moduleNo4}));
|
||||
|
||||
// When
|
||||
List<NativeModule> compositeModules = composite.createNativeModules(reactContext);
|
||||
@@ -112,8 +106,8 @@ public class CompositeReactPackageTest {
|
||||
|
||||
// Wrapping lists into sets to be order-independent.
|
||||
// Note that there should be no module2 returned.
|
||||
Set<NativeModule> expected = new HashSet<>(
|
||||
Arrays.asList(new NativeModule[]{moduleNo1, moduleNo3, moduleNo4}));
|
||||
Set<NativeModule> expected =
|
||||
new HashSet<>(Arrays.asList(new NativeModule[] {moduleNo1, moduleNo3, moduleNo4}));
|
||||
Set<NativeModule> actual = new HashSet<>(compositeModules);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
@@ -139,11 +133,11 @@ public class CompositeReactPackageTest {
|
||||
ViewManager managerNo4 = mock(ViewManager.class);
|
||||
when(managerNo4.getName()).thenReturn("ManagerNo4");
|
||||
|
||||
when(packageNo1.createViewManagers(reactContext)).thenReturn(
|
||||
Arrays.asList(new ViewManager[]{managerNo1, managerNo2}));
|
||||
when(packageNo1.createViewManagers(reactContext))
|
||||
.thenReturn(Arrays.asList(new ViewManager[] {managerNo1, managerNo2}));
|
||||
|
||||
when(packageNo2.createViewManagers(reactContext)).thenReturn(
|
||||
Arrays.asList(new ViewManager[]{managerNo3, managerNo4}));
|
||||
when(packageNo2.createViewManagers(reactContext))
|
||||
.thenReturn(Arrays.asList(new ViewManager[] {managerNo3, managerNo4}));
|
||||
|
||||
// When
|
||||
List<ViewManager> compositeModules = composite.createViewManagers(reactContext);
|
||||
@@ -152,9 +146,8 @@ public class CompositeReactPackageTest {
|
||||
|
||||
// Wrapping lists into sets to be order-independent.
|
||||
// Note that there should be no managerNo2 returned.
|
||||
Set<ViewManager> expected = new HashSet<>(
|
||||
Arrays.asList(new ViewManager[]{managerNo1, managerNo3, managerNo4})
|
||||
);
|
||||
Set<ViewManager> expected =
|
||||
new HashSet<>(Arrays.asList(new ViewManager[] {managerNo1, managerNo3, managerNo4}));
|
||||
Set<ViewManager> actual = new HashSet<>(compositeModules);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
@@ -1,46 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.common.SystemClock;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.events.Event;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Rule;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -50,13 +15,42 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.common.SystemClock;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.events.Event;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
import java.util.Date;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@PrepareForTest({Arguments.class, SystemClock.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class RootViewTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ReactContext mReactContext;
|
||||
private CatalystInstance mCatalystInstanceMock;
|
||||
@@ -65,25 +59,31 @@ public class RootViewTest {
|
||||
public void setUp() {
|
||||
final long ts = SystemClock.uptimeMillis();
|
||||
PowerMockito.mockStatic(Arguments.class);
|
||||
PowerMockito.when(Arguments.createArray()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createArray())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.mockStatic(SystemClock.class);
|
||||
PowerMockito.when(SystemClock.uptimeMillis()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return ts;
|
||||
}
|
||||
});
|
||||
PowerMockito.when(SystemClock.uptimeMillis())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return ts;
|
||||
}
|
||||
});
|
||||
|
||||
mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
|
||||
mReactContext = new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
@@ -103,8 +103,7 @@ public class RootViewTest {
|
||||
UIManagerModule uiManager = mock(UIManagerModule.class);
|
||||
EventDispatcher eventDispatcher = mock(EventDispatcher.class);
|
||||
RCTEventEmitter eventEmitterModuleMock = mock(RCTEventEmitter.class);
|
||||
when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class))
|
||||
.thenReturn(uiManager);
|
||||
when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class)).thenReturn(uiManager);
|
||||
when(uiManager.getEventDispatcher()).thenReturn(eventDispatcher);
|
||||
|
||||
int rootViewId = 7;
|
||||
@@ -117,8 +116,7 @@ public class RootViewTest {
|
||||
long ts = SystemClock.uptimeMillis();
|
||||
|
||||
// Test ACTION_DOWN event
|
||||
rootView.onTouchEvent(
|
||||
MotionEvent.obtain(100, ts, MotionEvent.ACTION_DOWN, 0, 0, 0));
|
||||
rootView.onTouchEvent(MotionEvent.obtain(100, ts, MotionEvent.ACTION_DOWN, 0, 0, 0));
|
||||
|
||||
ArgumentCaptor<Event> downEventCaptor = ArgumentCaptor.forClass(Event.class);
|
||||
verify(eventDispatcher).dispatchEvent(downEventCaptor.capture());
|
||||
@@ -128,29 +126,29 @@ public class RootViewTest {
|
||||
|
||||
ArgumentCaptor<JavaOnlyArray> downActionTouchesArgCaptor =
|
||||
ArgumentCaptor.forClass(JavaOnlyArray.class);
|
||||
verify(eventEmitterModuleMock).receiveTouches(
|
||||
eq("topTouchStart"),
|
||||
downActionTouchesArgCaptor.capture(),
|
||||
any(JavaOnlyArray.class));
|
||||
verify(eventEmitterModuleMock)
|
||||
.receiveTouches(
|
||||
eq("topTouchStart"), downActionTouchesArgCaptor.capture(), any(JavaOnlyArray.class));
|
||||
verifyNoMoreInteractions(eventEmitterModuleMock);
|
||||
|
||||
assertThat(downActionTouchesArgCaptor.getValue().size()).isEqualTo(1);
|
||||
assertThat(downActionTouchesArgCaptor.getValue().getMap(0)).isEqualTo(
|
||||
JavaOnlyMap.of(
|
||||
"pageX",
|
||||
0.,
|
||||
"pageY",
|
||||
0.,
|
||||
"locationX",
|
||||
0.,
|
||||
"locationY",
|
||||
0.,
|
||||
"target",
|
||||
rootViewId,
|
||||
"timestamp",
|
||||
(double) ts,
|
||||
"identifier",
|
||||
0.));
|
||||
assertThat(downActionTouchesArgCaptor.getValue().getMap(0))
|
||||
.isEqualTo(
|
||||
JavaOnlyMap.of(
|
||||
"pageX",
|
||||
0.,
|
||||
"pageY",
|
||||
0.,
|
||||
"locationX",
|
||||
0.,
|
||||
"locationY",
|
||||
0.,
|
||||
"target",
|
||||
rootViewId,
|
||||
"timestamp",
|
||||
(double) ts,
|
||||
"identifier",
|
||||
0.));
|
||||
|
||||
// Test ACTION_UP event
|
||||
reset(eventEmitterModuleMock, eventDispatcher);
|
||||
@@ -159,35 +157,34 @@ public class RootViewTest {
|
||||
ArgumentCaptor<JavaOnlyArray> upActionTouchesArgCaptor =
|
||||
ArgumentCaptor.forClass(JavaOnlyArray.class);
|
||||
|
||||
rootView.onTouchEvent(
|
||||
MotionEvent.obtain(50, ts, MotionEvent.ACTION_UP, 0, 0, 0));
|
||||
rootView.onTouchEvent(MotionEvent.obtain(50, ts, MotionEvent.ACTION_UP, 0, 0, 0));
|
||||
verify(eventDispatcher).dispatchEvent(upEventCaptor.capture());
|
||||
verifyNoMoreInteractions(eventDispatcher);
|
||||
|
||||
upEventCaptor.getValue().dispatch(eventEmitterModuleMock);
|
||||
verify(eventEmitterModuleMock).receiveTouches(
|
||||
eq("topTouchEnd"),
|
||||
upActionTouchesArgCaptor.capture(),
|
||||
any(WritableArray.class));
|
||||
verify(eventEmitterModuleMock)
|
||||
.receiveTouches(
|
||||
eq("topTouchEnd"), upActionTouchesArgCaptor.capture(), any(WritableArray.class));
|
||||
verifyNoMoreInteractions(eventEmitterModuleMock);
|
||||
|
||||
assertThat(upActionTouchesArgCaptor.getValue().size()).isEqualTo(1);
|
||||
assertThat(upActionTouchesArgCaptor.getValue().getMap(0)).isEqualTo(
|
||||
JavaOnlyMap.of(
|
||||
"pageX",
|
||||
0.,
|
||||
"pageY",
|
||||
0.,
|
||||
"locationX",
|
||||
0.,
|
||||
"locationY",
|
||||
0.,
|
||||
"target",
|
||||
rootViewId,
|
||||
"timestamp",
|
||||
(double) ts,
|
||||
"identifier",
|
||||
0.));
|
||||
assertThat(upActionTouchesArgCaptor.getValue().getMap(0))
|
||||
.isEqualTo(
|
||||
JavaOnlyMap.of(
|
||||
"pageX",
|
||||
0.,
|
||||
"pageY",
|
||||
0.,
|
||||
"locationX",
|
||||
0.,
|
||||
"locationY",
|
||||
0.,
|
||||
"target",
|
||||
rootViewId,
|
||||
"timestamp",
|
||||
(double) ts,
|
||||
"identifier",
|
||||
0.));
|
||||
|
||||
// Test other action
|
||||
reset(eventDispatcher);
|
||||
|
||||
+41
-39
@@ -1,18 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.animated;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests method used by {@link InterpolationAnimatedNode} to interpolate value of the input nodes.
|
||||
*/
|
||||
@@ -21,12 +20,11 @@ public class NativeAnimatedInterpolationTest {
|
||||
|
||||
private double simpleInterpolation(double value, double[] input, double[] output) {
|
||||
return InterpolationAnimatedNode.interpolate(
|
||||
value,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_EXTEND,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_EXTEND
|
||||
);
|
||||
value,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_EXTEND,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_EXTEND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,39 +80,43 @@ public class NativeAnimatedInterpolationTest {
|
||||
public void testClampExtrapolate() {
|
||||
double[] input = new double[] {10d, 20d};
|
||||
double[] output = new double[] {0d, 1d};
|
||||
assertThat(InterpolationAnimatedNode.interpolate(
|
||||
30d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP
|
||||
)).isEqualTo(1);
|
||||
assertThat(InterpolationAnimatedNode.interpolate(
|
||||
5d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP
|
||||
)).isEqualTo(0);
|
||||
assertThat(
|
||||
InterpolationAnimatedNode.interpolate(
|
||||
30d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP))
|
||||
.isEqualTo(1);
|
||||
assertThat(
|
||||
InterpolationAnimatedNode.interpolate(
|
||||
5d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_CLAMP))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdentityExtrapolate() {
|
||||
double[] input = new double[] {10d, 20d};
|
||||
double[] output = new double[] {0d, 1d};
|
||||
assertThat(InterpolationAnimatedNode.interpolate(
|
||||
30d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY
|
||||
)).isEqualTo(30);
|
||||
assertThat(InterpolationAnimatedNode.interpolate(
|
||||
5d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY
|
||||
)).isEqualTo(5);
|
||||
assertThat(
|
||||
InterpolationAnimatedNode.interpolate(
|
||||
30d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY))
|
||||
.isEqualTo(30);
|
||||
assertThat(
|
||||
InterpolationAnimatedNode.interpolate(
|
||||
5d,
|
||||
input,
|
||||
output,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY,
|
||||
InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY))
|
||||
.isEqualTo(5);
|
||||
}
|
||||
}
|
||||
|
||||
+348
-411
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.bridge;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
@@ -21,18 +19,13 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
/**
|
||||
* Tests for {@link BaseJavaModule} and {@link JavaModuleWrapper}
|
||||
*/
|
||||
/** Tests for {@link BaseJavaModule} and {@link JavaModuleWrapper} */
|
||||
@PrepareForTest({ReadableNativeArray.class, SoLoader.class})
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BaseJavaModuleTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private List<JavaModuleWrapper.MethodDescriptor> mMethods;
|
||||
private JavaModuleWrapper mWrapper;
|
||||
@@ -49,7 +42,7 @@ public class BaseJavaModuleTest {
|
||||
|
||||
private int findMethod(String mname, List<JavaModuleWrapper.MethodDescriptor> methods) {
|
||||
int posn = -1;
|
||||
for (int i = 0; i< methods.size(); i++) {
|
||||
for (int i = 0; i < methods.size(); i++) {
|
||||
JavaModuleWrapper.MethodDescriptor md = methods.get(i);
|
||||
if (md.name == mname) {
|
||||
posn = i;
|
||||
@@ -61,7 +54,7 @@ public class BaseJavaModuleTest {
|
||||
|
||||
@Test(expected = NativeArgumentsParseException.class)
|
||||
public void testCallMethodWithoutEnoughArgs() throws Exception {
|
||||
int methodId = findMethod("regularMethod",mMethods);
|
||||
int methodId = findMethod("regularMethod", mMethods);
|
||||
Mockito.stub(mArguments.size()).toReturn(1);
|
||||
mWrapper.invoke(methodId, mArguments);
|
||||
}
|
||||
|
||||
+47
-66
@@ -1,34 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.bridge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.common.logging.FakeLoggingDelegate;
|
||||
import com.facebook.common.logging.LoggingDelegate;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.fest.assertions.api.Assertions.fail;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.common.logging.FakeLoggingDelegate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FallbackJSBundleLoaderTest {
|
||||
|
||||
private static final String UNRECOVERABLE;
|
||||
|
||||
static {
|
||||
String prefix = FallbackJSBundleLoader.RECOVERABLE;
|
||||
char first = prefix.charAt(0);
|
||||
@@ -46,36 +42,31 @@ public class FallbackJSBundleLoaderTest {
|
||||
|
||||
@Test
|
||||
public void firstLoaderSucceeds() {
|
||||
JSBundleLoader delegates[] = new JSBundleLoader[] {
|
||||
successfulLoader("url1"),
|
||||
successfulLoader("url2")
|
||||
};
|
||||
JSBundleLoader delegates[] =
|
||||
new JSBundleLoader[] {successfulLoader("url1"), successfulLoader("url2")};
|
||||
|
||||
FallbackJSBundleLoader fallbackLoader =
|
||||
new FallbackJSBundleLoader(new ArrayList<>(Arrays.asList(delegates)));
|
||||
new FallbackJSBundleLoader(new ArrayList<>(Arrays.asList(delegates)));
|
||||
|
||||
assertThat(fallbackLoader.loadScript(null)).isEqualTo("url1");
|
||||
|
||||
verify(delegates[0], times(1)).loadScript(null);
|
||||
verify(delegates[1], never()).loadScript(null);
|
||||
|
||||
assertThat(mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF,
|
||||
FallbackJSBundleLoader.TAG,
|
||||
null))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
mLoggingDelegate.logContains(FakeLoggingDelegate.WTF, FallbackJSBundleLoader.TAG, null))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallingBackSuccessfully() {
|
||||
JSBundleLoader delegates[] = new JSBundleLoader[] {
|
||||
recoverableLoader("url1", "error1"),
|
||||
successfulLoader("url2"),
|
||||
successfulLoader("url3")
|
||||
};
|
||||
JSBundleLoader delegates[] =
|
||||
new JSBundleLoader[] {
|
||||
recoverableLoader("url1", "error1"), successfulLoader("url2"), successfulLoader("url3")
|
||||
};
|
||||
|
||||
FallbackJSBundleLoader fallbackLoader =
|
||||
new FallbackJSBundleLoader(new ArrayList<>(Arrays.asList(delegates)));
|
||||
new FallbackJSBundleLoader(new ArrayList<>(Arrays.asList(delegates)));
|
||||
|
||||
assertThat(fallbackLoader.loadScript(null)).isEqualTo("url2");
|
||||
|
||||
@@ -83,22 +74,21 @@ public class FallbackJSBundleLoaderTest {
|
||||
verify(delegates[1], times(1)).loadScript(null);
|
||||
verify(delegates[2], never()).loadScript(null);
|
||||
|
||||
assertThat(mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF,
|
||||
FallbackJSBundleLoader.TAG,
|
||||
recoverableMsg("error1")))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF, FallbackJSBundleLoader.TAG, recoverableMsg("error1")))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallingbackUnsuccessfully() {
|
||||
JSBundleLoader delegates[] = new JSBundleLoader[] {
|
||||
recoverableLoader("url1", "error1"),
|
||||
recoverableLoader("url2", "error2")
|
||||
};
|
||||
JSBundleLoader delegates[] =
|
||||
new JSBundleLoader[] {
|
||||
recoverableLoader("url1", "error1"), recoverableLoader("url2", "error2")
|
||||
};
|
||||
|
||||
FallbackJSBundleLoader fallbackLoader =
|
||||
new FallbackJSBundleLoader(new ArrayList<>(Arrays.asList(delegates)));
|
||||
new FallbackJSBundleLoader(new ArrayList<>(Arrays.asList(delegates)));
|
||||
|
||||
try {
|
||||
fallbackLoader.loadScript(null);
|
||||
@@ -113,36 +103,30 @@ public class FallbackJSBundleLoaderTest {
|
||||
cause = cause.getCause();
|
||||
}
|
||||
|
||||
assertThat(msgs).containsExactly(
|
||||
recoverableMsg("error1"),
|
||||
recoverableMsg("error2"));
|
||||
assertThat(msgs).containsExactly(recoverableMsg("error1"), recoverableMsg("error2"));
|
||||
}
|
||||
|
||||
verify(delegates[0], times(1)).loadScript(null);
|
||||
verify(delegates[1], times(1)).loadScript(null);
|
||||
|
||||
assertThat(mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF,
|
||||
FallbackJSBundleLoader.TAG,
|
||||
recoverableMsg("error1")))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF, FallbackJSBundleLoader.TAG, recoverableMsg("error1")))
|
||||
.isTrue();
|
||||
|
||||
assertThat(mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF,
|
||||
FallbackJSBundleLoader.TAG,
|
||||
recoverableMsg("error2")))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF, FallbackJSBundleLoader.TAG, recoverableMsg("error2")))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unrecoverable() {
|
||||
JSBundleLoader delegates[] = new JSBundleLoader[] {
|
||||
fatalLoader("url1", "error1"),
|
||||
recoverableLoader("url2", "error2")
|
||||
};
|
||||
JSBundleLoader delegates[] =
|
||||
new JSBundleLoader[] {fatalLoader("url1", "error1"), recoverableLoader("url2", "error2")};
|
||||
|
||||
FallbackJSBundleLoader fallbackLoader =
|
||||
new FallbackJSBundleLoader(new ArrayList(Arrays.asList(delegates)));
|
||||
new FallbackJSBundleLoader(new ArrayList(Arrays.asList(delegates)));
|
||||
|
||||
try {
|
||||
fallbackLoader.loadScript(null);
|
||||
@@ -154,11 +138,9 @@ public class FallbackJSBundleLoaderTest {
|
||||
verify(delegates[0], times(1)).loadScript(null);
|
||||
verify(delegates[1], never()).loadScript(null);
|
||||
|
||||
assertThat(mLoggingDelegate.logContains(
|
||||
FakeLoggingDelegate.WTF,
|
||||
FallbackJSBundleLoader.TAG,
|
||||
null))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
mLoggingDelegate.logContains(FakeLoggingDelegate.WTF, FallbackJSBundleLoader.TAG, null))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
private static JSBundleLoader successfulLoader(String url) {
|
||||
@@ -175,7 +157,7 @@ public class FallbackJSBundleLoaderTest {
|
||||
private static JSBundleLoader recoverableLoader(String url, String errMsg) {
|
||||
JSBundleLoader loader = mock(JSBundleLoader.class);
|
||||
when(loader.loadScript(null))
|
||||
.thenThrow(new RuntimeException(FallbackJSBundleLoader.RECOVERABLE + errMsg));
|
||||
.thenThrow(new RuntimeException(FallbackJSBundleLoader.RECOVERABLE + errMsg));
|
||||
|
||||
return loader;
|
||||
}
|
||||
@@ -186,8 +168,7 @@ public class FallbackJSBundleLoaderTest {
|
||||
|
||||
private static JSBundleLoader fatalLoader(String url, String errMsg) {
|
||||
JSBundleLoader loader = mock(JSBundleLoader.class);
|
||||
when(loader.loadScript(null))
|
||||
.thenThrow(new RuntimeException(UNRECOVERABLE + errMsg));
|
||||
when(loader.loadScript(null)).thenThrow(new RuntimeException(UNRECOVERABLE + errMsg));
|
||||
|
||||
return loader;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.bridge;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class InstanceHandleHelper {
|
||||
|
||||
@@ -1,42 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.bridge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JavaOnlyArray}
|
||||
*/
|
||||
import org.junit.Test;
|
||||
|
||||
/** Tests for {@link JavaOnlyArray} */
|
||||
public class JavaOnlyArrayTest {
|
||||
|
||||
@Test
|
||||
public void testGetType() throws Exception {
|
||||
JavaOnlyArray values = JavaOnlyArray.of(
|
||||
1,
|
||||
2f,
|
||||
3.,
|
||||
"4",
|
||||
false,
|
||||
JavaOnlyArray.of(),
|
||||
JavaOnlyMap.of(),
|
||||
null);
|
||||
ReadableType[] expectedTypes = new ReadableType[] {
|
||||
ReadableType.Number,
|
||||
ReadableType.Number,
|
||||
ReadableType.Number,
|
||||
ReadableType.String,
|
||||
ReadableType.Boolean,
|
||||
ReadableType.Array,
|
||||
ReadableType.Map,
|
||||
ReadableType.Null
|
||||
};
|
||||
JavaOnlyArray values =
|
||||
JavaOnlyArray.of(1, 2f, 3., "4", false, JavaOnlyArray.of(), JavaOnlyMap.of(), null);
|
||||
ReadableType[] expectedTypes =
|
||||
new ReadableType[] {
|
||||
ReadableType.Number,
|
||||
ReadableType.Number,
|
||||
ReadableType.Number,
|
||||
ReadableType.String,
|
||||
ReadableType.Boolean,
|
||||
ReadableType.Array,
|
||||
ReadableType.Map,
|
||||
ReadableType.Null
|
||||
};
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
assertThat(values.getType(i)).isEqualTo(expectedTypes[i]);
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.bridge;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class JsonWriterTest {
|
||||
private final StringWriter mStringWriter;
|
||||
private final JsonWriter mWriter;
|
||||
|
||||
@@ -1,56 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.bridge;
|
||||
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfigurationImpl;
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
|
||||
import com.facebook.react.bridge.queue.MessageQueueThreadSpec;
|
||||
import com.facebook.react.bridge.queue.QueueThreadExceptionHandler;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Utility for creating pre-configured instances of core react components for tests.
|
||||
*/
|
||||
import com.facebook.react.bridge.queue.MessageQueueThreadSpec;
|
||||
import com.facebook.react.bridge.queue.QueueThreadExceptionHandler;
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfigurationImpl;
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/** Utility for creating pre-configured instances of core react components for tests. */
|
||||
public class ReactTestHelper {
|
||||
|
||||
/**
|
||||
* @return a ReactApplicationContext that has a CatalystInstance mock returned by
|
||||
* {@link #createMockCatalystInstance}
|
||||
* @return a ReactApplicationContext that has a CatalystInstance mock returned by {@link
|
||||
* #createMockCatalystInstance}
|
||||
*/
|
||||
public static ReactApplicationContext createCatalystContextForTest() {
|
||||
ReactApplicationContext context =
|
||||
new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
ReactApplicationContext context = new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
context.initializeWithInstance(createMockCatalystInstance());
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a CatalystInstance mock that has a default working ReactQueueConfiguration.
|
||||
*/
|
||||
/** @return a CatalystInstance mock that has a default working ReactQueueConfiguration. */
|
||||
public static CatalystInstance createMockCatalystInstance() {
|
||||
ReactQueueConfigurationSpec spec = ReactQueueConfigurationSpec.builder()
|
||||
.setJSQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
|
||||
.setNativeModulesQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
|
||||
.build();
|
||||
ReactQueueConfiguration ReactQueueConfiguration = ReactQueueConfigurationImpl.create(
|
||||
spec,
|
||||
new QueueThreadExceptionHandler() {
|
||||
@Override
|
||||
public void handleException(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
ReactQueueConfigurationSpec spec =
|
||||
ReactQueueConfigurationSpec.builder()
|
||||
.setJSQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
|
||||
.setNativeModulesQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
|
||||
.build();
|
||||
ReactQueueConfiguration ReactQueueConfiguration =
|
||||
ReactQueueConfigurationImpl.create(
|
||||
spec,
|
||||
new QueueThreadExceptionHandler() {
|
||||
@Override
|
||||
public void handleException(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
CatalystInstance reactInstance = mock(CatalystInstance.class);
|
||||
when(reactInstance.getReactQueueConfiguration()).thenReturn(ReactQueueConfiguration);
|
||||
|
||||
+38
-44
@@ -9,19 +9,18 @@ package com.facebook.react.devsupport;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import com.facebook.react.common.StandardCharsets;
|
||||
import com.facebook.react.devsupport.BundleDeltaClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import okio.BufferedSource;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import okio.Okio;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BundleDeltaClientTest {
|
||||
@@ -72,12 +71,7 @@ public class BundleDeltaClientTest {
|
||||
+ "\"deleted\": [1]"
|
||||
+ "}"),
|
||||
file);
|
||||
assertThat(contentOf(file))
|
||||
.isEqualTo(
|
||||
"pre\n"
|
||||
+ "0.1\n"
|
||||
+ "2\n"
|
||||
+ "post\n");
|
||||
assertThat(contentOf(file)).isEqualTo("pre\n" + "0.1\n" + "2\n" + "post\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,34 +95,34 @@ public class BundleDeltaClientTest {
|
||||
+ "console.log('That is all folks!');\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortsModulesByIdInPatchedBundle() throws IOException {
|
||||
File file = mFolder.newFile();
|
||||
mClient.processDelta(
|
||||
bufferedSource(
|
||||
"{"
|
||||
+ "\"pre\": \"console.log('Hello World!');\","
|
||||
+ "\"post\": \"console.log('That is all folks!');\","
|
||||
+ "\"modules\": [[3, \"3\"], [0, \"0\"], [1, \"1\"]]"
|
||||
+ "}"),
|
||||
file);
|
||||
file = mFolder.newFile();
|
||||
mClient.processDelta(
|
||||
bufferedSource(
|
||||
"{"
|
||||
+ "\"added\": [[2, \"2\"]],"
|
||||
+ "\"modified\": [[0, \"0.1\"]],"
|
||||
+ "\"deleted\": [1]"
|
||||
+ "}"),
|
||||
file);
|
||||
assertThat(contentOf(file))
|
||||
.isEqualTo(
|
||||
"console.log('Hello World!');\n"
|
||||
+ "0.1\n"
|
||||
+ "2\n"
|
||||
+ "3\n"
|
||||
+ "console.log('That is all folks!');\n");
|
||||
}
|
||||
@Test
|
||||
public void testSortsModulesByIdInPatchedBundle() throws IOException {
|
||||
File file = mFolder.newFile();
|
||||
mClient.processDelta(
|
||||
bufferedSource(
|
||||
"{"
|
||||
+ "\"pre\": \"console.log('Hello World!');\","
|
||||
+ "\"post\": \"console.log('That is all folks!');\","
|
||||
+ "\"modules\": [[3, \"3\"], [0, \"0\"], [1, \"1\"]]"
|
||||
+ "}"),
|
||||
file);
|
||||
file = mFolder.newFile();
|
||||
mClient.processDelta(
|
||||
bufferedSource(
|
||||
"{"
|
||||
+ "\"added\": [[2, \"2\"]],"
|
||||
+ "\"modified\": [[0, \"0.1\"]],"
|
||||
+ "\"deleted\": [1]"
|
||||
+ "}"),
|
||||
file);
|
||||
assertThat(contentOf(file))
|
||||
.isEqualTo(
|
||||
"console.log('Hello World!');\n"
|
||||
+ "0.1\n"
|
||||
+ "2\n"
|
||||
+ "3\n"
|
||||
+ "console.log('That is all folks!');\n");
|
||||
}
|
||||
|
||||
private static BufferedSource bufferedSource(String string) {
|
||||
return Okio.buffer(
|
||||
|
||||
+27
-26
@@ -1,14 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.devsupport;
|
||||
|
||||
import com.facebook.react.common.JavascriptException;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import com.facebook.react.common.JavascriptException;
|
||||
import java.util.HashMap;
|
||||
import okio.ByteString;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -18,35 +20,28 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import okio.ByteString;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@PrepareForTest({ JSDebuggerWebSocketClient.class })
|
||||
@PrepareForTest({JSDebuggerWebSocketClient.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class JSDebuggerWebSocketClientTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Test
|
||||
public void test_prepareJSRuntime_ShouldSendCorrectMessage() throws Exception {
|
||||
final JSDebuggerWebSocketClient.JSDebuggerCallback cb =
|
||||
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
|
||||
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
|
||||
|
||||
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
|
||||
client.prepareJSRuntime(cb);
|
||||
PowerMockito.verifyPrivate(client).invoke("sendMessage", 0,
|
||||
"{\"id\":0,\"method\":\"prepareJSRuntime\"}");
|
||||
PowerMockito.verifyPrivate(client)
|
||||
.invoke("sendMessage", 0, "{\"id\":0,\"method\":\"prepareJSRuntime\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadApplicationScript_ShouldSendCorrectMessage() throws Exception {
|
||||
final JSDebuggerWebSocketClient.JSDebuggerCallback cb =
|
||||
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
|
||||
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
|
||||
|
||||
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
|
||||
HashMap<String, String> injectedObjects = new HashMap<>();
|
||||
@@ -54,21 +49,24 @@ public class JSDebuggerWebSocketClientTest {
|
||||
injectedObjects.put("key2", "value2");
|
||||
|
||||
client.loadApplicationScript("http://localhost:8080/index.js", injectedObjects, cb);
|
||||
PowerMockito.verifyPrivate(client).invoke("sendMessage", 0,
|
||||
"{\"id\":0,\"method\":\"executeApplicationScript\",\"url\":\"http://localhost:8080/index.js\"" +
|
||||
",\"inject\":{\"key1\":\"value1\",\"key2\":\"value2\"}}");
|
||||
PowerMockito.verifyPrivate(client)
|
||||
.invoke(
|
||||
"sendMessage",
|
||||
0,
|
||||
"{\"id\":0,\"method\":\"executeApplicationScript\",\"url\":\"http://localhost:8080/index.js\""
|
||||
+ ",\"inject\":{\"key1\":\"value1\",\"key2\":\"value2\"}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_executeJSCall_ShouldSendCorrectMessage() throws Exception {
|
||||
final JSDebuggerWebSocketClient.JSDebuggerCallback cb =
|
||||
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
|
||||
PowerMockito.mock(JSDebuggerWebSocketClient.JSDebuggerCallback.class);
|
||||
|
||||
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
|
||||
|
||||
client.executeJSCall("foo", "[1,2,3]", cb);
|
||||
PowerMockito.verifyPrivate(client).invoke("sendMessage", 0,
|
||||
"{\"id\":0,\"method\":\"foo\",\"arguments\":[1,2,3]}");
|
||||
PowerMockito.verifyPrivate(client)
|
||||
.invoke("sendMessage", 0, "{\"id\":0,\"method\":\"foo\",\"arguments\":[1,2,3]}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +74,8 @@ public class JSDebuggerWebSocketClientTest {
|
||||
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
|
||||
|
||||
client.onMessage(null, ByteString.encodeUtf8("{\"replyID\":0, \"result\":\"OK\"}"));
|
||||
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString());
|
||||
PowerMockito.verifyPrivate(client, never())
|
||||
.invoke("triggerRequestSuccess", anyInt(), anyString());
|
||||
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
|
||||
}
|
||||
|
||||
@@ -85,7 +84,8 @@ public class JSDebuggerWebSocketClientTest {
|
||||
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
|
||||
|
||||
client.onMessage(null, "{\"result\":\"OK\"}");
|
||||
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString());
|
||||
PowerMockito.verifyPrivate(client, never())
|
||||
.invoke("triggerRequestSuccess", anyInt(), anyString());
|
||||
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
|
||||
}
|
||||
|
||||
@@ -94,7 +94,8 @@ public class JSDebuggerWebSocketClientTest {
|
||||
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
|
||||
|
||||
client.onMessage(null, "{\"replyID\":null, \"result\":\"OK\"}");
|
||||
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString());
|
||||
PowerMockito.verifyPrivate(client, never())
|
||||
.invoke("triggerRequestSuccess", anyInt(), anyString());
|
||||
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
|
||||
}
|
||||
|
||||
|
||||
+60
-56
@@ -1,23 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.devsupport;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import okio.Buffer;
|
||||
import okio.ByteString;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MultipartStreamReaderTest {
|
||||
@@ -26,14 +23,14 @@ public class MultipartStreamReaderTest {
|
||||
private int mCount = 0;
|
||||
|
||||
@Override
|
||||
public void onChunkComplete(Map<String, String> headers, Buffer body, boolean done) throws IOException {
|
||||
public void onChunkComplete(Map<String, String> headers, Buffer body, boolean done)
|
||||
throws IOException {
|
||||
mCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkProgress(Map<String, String> headers, long loaded, long total) throws IOException {
|
||||
|
||||
}
|
||||
public void onChunkProgress(Map<String, String> headers, long loaded, long total)
|
||||
throws IOException {}
|
||||
|
||||
public int getCallCount() {
|
||||
return mCount;
|
||||
@@ -42,30 +39,33 @@ public class MultipartStreamReaderTest {
|
||||
|
||||
@Test
|
||||
public void testSimpleCase() throws IOException {
|
||||
ByteString response = ByteString.encodeUtf8(
|
||||
"preable, should be ignored\r\n" +
|
||||
"--sample_boundary\r\n" +
|
||||
"Content-Type: application/json; charset=utf-8\r\n" +
|
||||
"Content-Length: 2\r\n\r\n" +
|
||||
"{}\r\n" +
|
||||
"--sample_boundary--\r\n" +
|
||||
"epilogue, should be ignored");
|
||||
ByteString response =
|
||||
ByteString.encodeUtf8(
|
||||
"preable, should be ignored\r\n"
|
||||
+ "--sample_boundary\r\n"
|
||||
+ "Content-Type: application/json; charset=utf-8\r\n"
|
||||
+ "Content-Length: 2\r\n\r\n"
|
||||
+ "{}\r\n"
|
||||
+ "--sample_boundary--\r\n"
|
||||
+ "epilogue, should be ignored");
|
||||
|
||||
Buffer source = new Buffer();
|
||||
source.write(response);
|
||||
|
||||
MultipartStreamReader reader = new MultipartStreamReader(source, "sample_boundary");
|
||||
|
||||
CallCountTrackingChunkCallback callback = new CallCountTrackingChunkCallback() {
|
||||
@Override
|
||||
public void onChunkComplete(Map<String, String> headers, Buffer body, boolean done) throws IOException {
|
||||
super.onChunkComplete(headers, body, done);
|
||||
CallCountTrackingChunkCallback callback =
|
||||
new CallCountTrackingChunkCallback() {
|
||||
@Override
|
||||
public void onChunkComplete(Map<String, String> headers, Buffer body, boolean done)
|
||||
throws IOException {
|
||||
super.onChunkComplete(headers, body, done);
|
||||
|
||||
assertThat(done).isTrue();
|
||||
assertThat(headers.get("Content-Type")).isEqualTo("application/json; charset=utf-8");
|
||||
assertThat(body.readUtf8()).isEqualTo("{}");
|
||||
}
|
||||
};
|
||||
assertThat(done).isTrue();
|
||||
assertThat(headers.get("Content-Type")).isEqualTo("application/json; charset=utf-8");
|
||||
assertThat(body.readUtf8()).isEqualTo("{}");
|
||||
}
|
||||
};
|
||||
boolean success = reader.readAllParts(callback);
|
||||
|
||||
assertThat(callback.getCallCount()).isEqualTo(1);
|
||||
@@ -74,31 +74,34 @@ public class MultipartStreamReaderTest {
|
||||
|
||||
@Test
|
||||
public void testMultipleParts() throws IOException {
|
||||
ByteString response = ByteString.encodeUtf8(
|
||||
"preable, should be ignored\r\n" +
|
||||
"--sample_boundary\r\n" +
|
||||
"1\r\n" +
|
||||
"--sample_boundary\r\n" +
|
||||
"2\r\n" +
|
||||
"--sample_boundary\r\n" +
|
||||
"3\r\n" +
|
||||
"--sample_boundary--\r\n" +
|
||||
"epilogue, should be ignored");
|
||||
ByteString response =
|
||||
ByteString.encodeUtf8(
|
||||
"preable, should be ignored\r\n"
|
||||
+ "--sample_boundary\r\n"
|
||||
+ "1\r\n"
|
||||
+ "--sample_boundary\r\n"
|
||||
+ "2\r\n"
|
||||
+ "--sample_boundary\r\n"
|
||||
+ "3\r\n"
|
||||
+ "--sample_boundary--\r\n"
|
||||
+ "epilogue, should be ignored");
|
||||
|
||||
Buffer source = new Buffer();
|
||||
source.write(response);
|
||||
|
||||
MultipartStreamReader reader = new MultipartStreamReader(source, "sample_boundary");
|
||||
|
||||
CallCountTrackingChunkCallback callback = new CallCountTrackingChunkCallback() {
|
||||
@Override
|
||||
public void onChunkComplete(Map<String, String> headers, Buffer body, boolean done) throws IOException {
|
||||
super.onChunkComplete(headers, body, done);
|
||||
CallCountTrackingChunkCallback callback =
|
||||
new CallCountTrackingChunkCallback() {
|
||||
@Override
|
||||
public void onChunkComplete(Map<String, String> headers, Buffer body, boolean done)
|
||||
throws IOException {
|
||||
super.onChunkComplete(headers, body, done);
|
||||
|
||||
assertThat(done).isEqualTo(getCallCount() == 3);
|
||||
assertThat(body.readUtf8()).isEqualTo(String.valueOf(getCallCount()));
|
||||
}
|
||||
};
|
||||
assertThat(done).isEqualTo(getCallCount() == 3);
|
||||
assertThat(body.readUtf8()).isEqualTo(String.valueOf(getCallCount()));
|
||||
}
|
||||
};
|
||||
boolean success = reader.readAllParts(callback);
|
||||
|
||||
assertThat(callback.getCallCount()).isEqualTo(3);
|
||||
@@ -123,14 +126,15 @@ public class MultipartStreamReaderTest {
|
||||
|
||||
@Test
|
||||
public void testNoCloseDelimiter() throws IOException {
|
||||
ByteString response = ByteString.encodeUtf8(
|
||||
"preable, should be ignored\r\n" +
|
||||
"--sample_boundary\r\n" +
|
||||
"Content-Type: application/json; charset=utf-8\r\n" +
|
||||
"Content-Length: 2\r\n\r\n" +
|
||||
"{}\r\n" +
|
||||
"--sample_boundary\r\n" +
|
||||
"incomplete message...");
|
||||
ByteString response =
|
||||
ByteString.encodeUtf8(
|
||||
"preable, should be ignored\r\n"
|
||||
+ "--sample_boundary\r\n"
|
||||
+ "Content-Type: application/json; charset=utf-8\r\n"
|
||||
+ "Content-Length: 2\r\n\r\n"
|
||||
+ "{}\r\n"
|
||||
+ "--sample_boundary\r\n"
|
||||
+ "incomplete message...");
|
||||
|
||||
Buffer source = new Buffer();
|
||||
source.write(response);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.devsupport;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
@@ -19,8 +18,8 @@ public class StackTraceHelperTest {
|
||||
|
||||
@Test
|
||||
public void testParseAlternateFormatStackFrameWithMethod() {
|
||||
final StackFrame frame = StackTraceHelper.convertJsStackTrace(
|
||||
"at func1 (/path/to/file.js:2:18)")[0];
|
||||
final StackFrame frame =
|
||||
StackTraceHelper.convertJsStackTrace("at func1 (/path/to/file.js:2:18)")[0];
|
||||
assertThat(frame.getMethod()).isEqualTo("func1");
|
||||
assertThat(frame.getFileName()).isEqualTo("file.js");
|
||||
assertThat(frame.getLine()).isEqualTo(2);
|
||||
@@ -29,8 +28,7 @@ public class StackTraceHelperTest {
|
||||
|
||||
@Test
|
||||
public void testParseStackFrameWithMethod() {
|
||||
final StackFrame frame = StackTraceHelper.convertJsStackTrace(
|
||||
"render@Test.bundle:1:2000")[0];
|
||||
final StackFrame frame = StackTraceHelper.convertJsStackTrace("render@Test.bundle:1:2000")[0];
|
||||
assertThat(frame.getMethod()).isEqualTo("render");
|
||||
assertThat(frame.getFileName()).isEqualTo("Test.bundle");
|
||||
assertThat(frame.getLine()).isEqualTo(1);
|
||||
@@ -39,8 +37,7 @@ public class StackTraceHelperTest {
|
||||
|
||||
@Test
|
||||
public void testParseStackFrameWithoutMethod() {
|
||||
final StackFrame frame = StackTraceHelper.convertJsStackTrace(
|
||||
"Test.bundle:1:2000")[0];
|
||||
final StackFrame frame = StackTraceHelper.convertJsStackTrace("Test.bundle:1:2000")[0];
|
||||
assertThat(frame.getMethod()).isEqualTo("(unknown)");
|
||||
assertThat(frame.getFileName()).isEqualTo("Test.bundle");
|
||||
assertThat(frame.getLine()).isEqualTo(1);
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.blob;
|
||||
|
||||
import android.net.Uri;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -29,16 +35,6 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@PrepareForTest({Arguments.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
@@ -49,18 +45,19 @@ public class BlobModuleTest {
|
||||
private String mBlobId;
|
||||
private BlobModule mBlobModule;
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Before
|
||||
public void prepareModules() throws Exception {
|
||||
PowerMockito.mockStatic(Arguments.class);
|
||||
Mockito.when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
Mockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
|
||||
mBytes = new byte[120];
|
||||
new Random().nextBytes(mBytes);
|
||||
@@ -83,11 +80,12 @@ public class BlobModuleTest {
|
||||
|
||||
@Test
|
||||
public void testResolveUri() {
|
||||
Uri uri = new Uri.Builder()
|
||||
.appendPath(mBlobId)
|
||||
.appendQueryParameter("offset", "0")
|
||||
.appendQueryParameter("size", String.valueOf(mBytes.length))
|
||||
.build();
|
||||
Uri uri =
|
||||
new Uri.Builder()
|
||||
.appendPath(mBlobId)
|
||||
.appendQueryParameter("offset", "0")
|
||||
.appendQueryParameter("size", String.valueOf(mBytes.length))
|
||||
.build();
|
||||
|
||||
assertArrayEquals(mBytes, mBlobModule.resolve(uri));
|
||||
}
|
||||
|
||||
+15
-20
@@ -1,30 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.camera;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Base64InputStream;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Base64InputStream;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ImageStoreManagerTest {
|
||||
@@ -57,9 +54,7 @@ public class ImageStoreManagerTest {
|
||||
assertFalse(invokeConversion(inputStream).contains("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Just to test if using the ByteArrayInputStream isn't missing something
|
||||
*/
|
||||
/** Just to test if using the ByteArrayInputStream isn't missing something */
|
||||
@Test
|
||||
public void itDoesNotAddLineBreaks_whenBase64InputStream() throws IOException {
|
||||
byte[] exampleString = "dGVzdA==".getBytes();
|
||||
|
||||
+7
-12
@@ -1,30 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.clipboard;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.ClipboardManager;
|
||||
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.modules.clipboard.ClipboardModule;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@SuppressLint({"ClipboardManager", "DeprecatedClass"})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
@@ -39,7 +33,8 @@ public class ClipboardModuleTest {
|
||||
public void setUp() {
|
||||
mClipboardModule = new ClipboardModule(RuntimeEnvironment.application);
|
||||
mClipboardManager =
|
||||
(ClipboardManager) RuntimeEnvironment.application.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
(ClipboardManager)
|
||||
RuntimeEnvironment.application.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+12
-21
@@ -1,20 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.dialog;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -25,12 +26,6 @@ import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.util.ActivityController;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class DialogModuleTest {
|
||||
@@ -39,7 +34,7 @@ public class DialogModuleTest {
|
||||
private FragmentActivity mActivity;
|
||||
private DialogModule mDialogModule;
|
||||
|
||||
final static class SimpleCallback implements Callback {
|
||||
static final class SimpleCallback implements Callback {
|
||||
private Object[] mArgs;
|
||||
private int mCalls;
|
||||
|
||||
@@ -61,11 +56,7 @@ public class DialogModuleTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mActivityController = Robolectric.buildActivity(FragmentActivity.class);
|
||||
mActivity = mActivityController
|
||||
.create()
|
||||
.start()
|
||||
.resume()
|
||||
.get();
|
||||
mActivity = mActivityController.create().start().resume().get();
|
||||
|
||||
final ReactApplicationContext context = PowerMockito.mock(ReactApplicationContext.class);
|
||||
PowerMockito.when(context.hasActiveCatalystInstance()).thenReturn(true);
|
||||
@@ -167,7 +158,7 @@ public class DialogModuleTest {
|
||||
}
|
||||
|
||||
private AlertFragment getFragment() {
|
||||
return (AlertFragment) mActivity.getSupportFragmentManager()
|
||||
.findFragmentByTag(DialogModule.FRAGMENT_TAG);
|
||||
return (AlertFragment)
|
||||
mActivity.getSupportFragmentManager().findFragmentByTag(DialogModule.FRAGMENT_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.network;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HeaderUtilTest {
|
||||
public static final String TABULATION_TEST = "\teyJhbGciOiJS\t";
|
||||
public static final String TABULATION_STRIP_EXPECTED = "eyJhbGciOiJS";
|
||||
@@ -24,7 +23,6 @@ public class HeaderUtilTest {
|
||||
@Test
|
||||
public void nameStripKeepsLetters() {
|
||||
assertEquals(ALPHABET_TEST, HeaderUtil.stripHeaderName(ALPHABET_TEST));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -35,7 +33,6 @@ public class HeaderUtilTest {
|
||||
@Test
|
||||
public void nameStripKeepsNumbers() {
|
||||
assertEquals(NUMBERS_TEST, HeaderUtil.stripHeaderName(NUMBERS_TEST));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,5 +69,4 @@ public class HeaderUtilTest {
|
||||
public void nameStripRemovesExtraSymbols() {
|
||||
assertEquals(BANNED_TEST_EXPECTED, HeaderUtil.stripHeaderName(NAME_BANNED_SYMBOLS_TEST));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+325
-307
@@ -1,15 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.network;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
@@ -21,7 +24,9 @@ import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.common.StandardCharsets;
|
||||
import com.facebook.react.common.network.OkHttpCallUtil;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
@@ -43,62 +48,54 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link NetworkingModule}.
|
||||
*/
|
||||
/** Tests for {@link NetworkingModule}. */
|
||||
@PrepareForTest({
|
||||
Arguments.class,
|
||||
Call.class,
|
||||
RequestBodyUtil.class,
|
||||
ProgressRequestBody.class,
|
||||
ProgressListener.class,
|
||||
MultipartBody.class,
|
||||
MultipartBody.Builder.class,
|
||||
NetworkingModule.class,
|
||||
OkHttpClient.class,
|
||||
OkHttpClient.Builder.class,
|
||||
OkHttpCallUtil.class})
|
||||
Arguments.class,
|
||||
Call.class,
|
||||
RequestBodyUtil.class,
|
||||
ProgressRequestBody.class,
|
||||
ProgressListener.class,
|
||||
MultipartBody.class,
|
||||
MultipartBody.Builder.class,
|
||||
NetworkingModule.class,
|
||||
OkHttpClient.class,
|
||||
OkHttpClient.Builder.class,
|
||||
OkHttpCallUtil.class
|
||||
})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class NetworkingModuleTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Test
|
||||
public void testGetWithoutHeaders() throws Exception {
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"GET",
|
||||
"http://somedomain/foo",
|
||||
/* requestId */ 0,
|
||||
/* headers */ JavaOnlyArray.of(),
|
||||
/* body */ null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"GET",
|
||||
"http://somedomain/foo",
|
||||
/* requestId */ 0,
|
||||
/* headers */ JavaOnlyArray.of(),
|
||||
/* body */ null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
@@ -125,15 +122,15 @@ public class NetworkingModuleTest {
|
||||
mockEvents();
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"GET",
|
||||
"http://somedoman/foo",
|
||||
/* requestId */ 0,
|
||||
/* headers */ JavaOnlyArray.from(invalidHeaders),
|
||||
/* body */ null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"GET",
|
||||
"http://somedoman/foo",
|
||||
/* requestId */ 0,
|
||||
/* headers */ JavaOnlyArray.from(invalidHeaders),
|
||||
/* body */ null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
verifyErrorEmit(emitter, 0);
|
||||
}
|
||||
@@ -156,15 +153,15 @@ public class NetworkingModuleTest {
|
||||
mockEvents();
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
verifyErrorEmit(emitter, 0);
|
||||
}
|
||||
@@ -184,15 +181,15 @@ public class NetworkingModuleTest {
|
||||
mockEvents();
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"GET",
|
||||
"aaa",
|
||||
/* requestId */ 0,
|
||||
/* headers */ JavaOnlyArray.of(),
|
||||
/* body */ null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"GET",
|
||||
"aaa",
|
||||
/* requestId */ 0,
|
||||
/* headers */ JavaOnlyArray.of(),
|
||||
/* body */ null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
verifyErrorEmit(emitter, 0);
|
||||
}
|
||||
@@ -208,21 +205,23 @@ public class NetworkingModuleTest {
|
||||
|
||||
private static void mockEvents() {
|
||||
PowerMockito.mockStatic(Arguments.class);
|
||||
Mockito.when(Arguments.createArray()).thenAnswer(
|
||||
new Answer<WritableArray>() {
|
||||
@Override
|
||||
public WritableArray answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
Mockito.when(Arguments.createArray())
|
||||
.thenAnswer(
|
||||
new Answer<WritableArray>() {
|
||||
@Override
|
||||
public WritableArray answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
|
||||
Mockito.when(Arguments.createMap()).thenAnswer(
|
||||
new Answer<WritableMap>() {
|
||||
@Override
|
||||
public WritableMap answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
Mockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<WritableMap>() {
|
||||
@Override
|
||||
public WritableMap answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,13 +231,15 @@ public class NetworkingModuleTest {
|
||||
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
|
||||
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
@@ -250,15 +251,15 @@ public class NetworkingModuleTest {
|
||||
mockEvents();
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "text/plain")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "text/plain")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
@@ -275,33 +276,36 @@ public class NetworkingModuleTest {
|
||||
@Test
|
||||
public void testHeaders() throws Exception {
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
|
||||
List<JavaOnlyArray> headers = Arrays.asList(
|
||||
JavaOnlyArray.of("Accept", "text/plain"),
|
||||
JavaOnlyArray.of("User-Agent", "React test agent/1.0"));
|
||||
List<JavaOnlyArray> headers =
|
||||
Arrays.asList(
|
||||
JavaOnlyArray.of("Accept", "text/plain"),
|
||||
JavaOnlyArray.of("User-Agent", "React test agent/1.0"));
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"GET",
|
||||
"http://someurl/baz",
|
||||
0,
|
||||
JavaOnlyArray.from(headers),
|
||||
null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"GET",
|
||||
"http://someurl/baz",
|
||||
0,
|
||||
JavaOnlyArray.from(headers),
|
||||
null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
Headers requestHeaders = argumentCaptor.getValue().headers();
|
||||
@@ -313,38 +317,41 @@ public class NetworkingModuleTest {
|
||||
@Test
|
||||
public void testPostJsonContentTypeHeader() throws Exception {
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
|
||||
JavaOnlyMap body = new JavaOnlyMap();
|
||||
body.putString("string", "{ \"key\": \"value\" }");
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "application/json")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "application/json")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
|
||||
// Verify okhttp does not append "charset=utf-8"
|
||||
assertThat(argumentCaptor.getValue().body().contentType().toString()).isEqualTo("application/json");
|
||||
assertThat(argumentCaptor.getValue().body().contentType().toString())
|
||||
.isEqualTo("application/json");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -354,13 +361,15 @@ public class NetworkingModuleTest {
|
||||
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
|
||||
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
@@ -372,15 +381,15 @@ public class NetworkingModuleTest {
|
||||
mockEvents();
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "text/plain; charset=utf-16")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "text/plain; charset=utf-16")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
@@ -397,13 +406,15 @@ public class NetworkingModuleTest {
|
||||
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
|
||||
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
@@ -415,15 +426,15 @@ public class NetworkingModuleTest {
|
||||
mockEvents();
|
||||
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "invalid")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://somedomain/bar",
|
||||
0,
|
||||
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "invalid")),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
@@ -451,46 +462,45 @@ public class NetworkingModuleTest {
|
||||
bodyPart.putString("string", "value");
|
||||
bodyPart.putArray(
|
||||
"headers",
|
||||
JavaOnlyArray.from(
|
||||
Arrays.asList(
|
||||
JavaOnlyArray.of("content-disposition", "name"))));
|
||||
JavaOnlyArray.from(Arrays.asList(JavaOnlyArray.of("content-disposition", "name"))));
|
||||
formData.pushMap(bodyPart);
|
||||
body.putArray("formData", formData);
|
||||
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://someurl/uploadFoo",
|
||||
0,
|
||||
new JavaOnlyArray(),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://someurl/uploadFoo",
|
||||
0,
|
||||
new JavaOnlyArray(),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
// verify url, method, headers
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://someurl/uploadFoo");
|
||||
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
|
||||
assertThat(argumentCaptor.getValue().body().contentType().type()).
|
||||
isEqualTo(MultipartBody.FORM.type());
|
||||
assertThat(argumentCaptor.getValue().body().contentType().subtype()).
|
||||
isEqualTo(MultipartBody.FORM.subtype());
|
||||
assertThat(argumentCaptor.getValue().body().contentType().type())
|
||||
.isEqualTo(MultipartBody.FORM.type());
|
||||
assertThat(argumentCaptor.getValue().body().contentType().subtype())
|
||||
.isEqualTo(MultipartBody.FORM.subtype());
|
||||
Headers requestHeaders = argumentCaptor.getValue().headers();
|
||||
assertThat(requestHeaders.size()).isEqualTo(1);
|
||||
}
|
||||
@@ -505,7 +515,8 @@ public class NetworkingModuleTest {
|
||||
when(RequestBodyUtil.createProgressRequest(any(RequestBody.class), any(ProgressListener.class)))
|
||||
.thenCallRealMethod();
|
||||
|
||||
List<JavaOnlyArray> headers = Arrays.asList(
|
||||
List<JavaOnlyArray> headers =
|
||||
Arrays.asList(
|
||||
JavaOnlyArray.of("Accept", "text/plain"),
|
||||
JavaOnlyArray.of("User-Agent", "React test agent/1.0"),
|
||||
JavaOnlyArray.of("content-type", "multipart/form-data"));
|
||||
@@ -516,46 +527,45 @@ public class NetworkingModuleTest {
|
||||
bodyPart.putString("string", "value");
|
||||
bodyPart.putArray(
|
||||
"headers",
|
||||
JavaOnlyArray.from(
|
||||
Arrays.asList(
|
||||
JavaOnlyArray.of("content-disposition", "name"))));
|
||||
JavaOnlyArray.from(Arrays.asList(JavaOnlyArray.of("content-disposition", "name"))));
|
||||
formData.pushMap(bodyPart);
|
||||
body.putArray("formData", formData);
|
||||
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://someurl/uploadFoo",
|
||||
0,
|
||||
JavaOnlyArray.from(headers),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://someurl/uploadFoo",
|
||||
0,
|
||||
JavaOnlyArray.from(headers),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
// verify url, method, headers
|
||||
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
|
||||
verify(httpClient).newCall(argumentCaptor.capture());
|
||||
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://someurl/uploadFoo");
|
||||
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
|
||||
assertThat(argumentCaptor.getValue().body().contentType().type()).
|
||||
isEqualTo(MultipartBody.FORM.type());
|
||||
assertThat(argumentCaptor.getValue().body().contentType().subtype()).
|
||||
isEqualTo(MultipartBody.FORM.subtype());
|
||||
assertThat(argumentCaptor.getValue().body().contentType().type())
|
||||
.isEqualTo(MultipartBody.FORM.type());
|
||||
assertThat(argumentCaptor.getValue().body().contentType().subtype())
|
||||
.isEqualTo(MultipartBody.FORM.subtype());
|
||||
Headers requestHeaders = argumentCaptor.getValue().headers();
|
||||
assertThat(requestHeaders.size()).isEqualTo(3);
|
||||
assertThat(requestHeaders.get("Accept")).isEqualTo("text/plain");
|
||||
@@ -575,31 +585,36 @@ public class NetworkingModuleTest {
|
||||
when(inputStream.available()).thenReturn("imageUri".length());
|
||||
|
||||
final MultipartBody.Builder multipartBuilder = mock(MultipartBody.Builder.class);
|
||||
PowerMockito.whenNew(MultipartBody.Builder.class).withNoArguments().thenReturn(multipartBuilder);
|
||||
when(multipartBuilder.setType(any(MediaType.class))).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return multipartBuilder;
|
||||
}
|
||||
});
|
||||
when(multipartBuilder.addPart(any(Headers.class), any(RequestBody.class))).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return multipartBuilder;
|
||||
}
|
||||
});
|
||||
when(multipartBuilder.build()).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return mock(MultipartBody.class);
|
||||
}
|
||||
});
|
||||
PowerMockito.whenNew(MultipartBody.Builder.class)
|
||||
.withNoArguments()
|
||||
.thenReturn(multipartBuilder);
|
||||
when(multipartBuilder.setType(any(MediaType.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return multipartBuilder;
|
||||
}
|
||||
});
|
||||
when(multipartBuilder.addPart(any(Headers.class), any(RequestBody.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return multipartBuilder;
|
||||
}
|
||||
});
|
||||
when(multipartBuilder.build())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return mock(MultipartBody.class);
|
||||
}
|
||||
});
|
||||
|
||||
List<JavaOnlyArray> headers = Arrays.asList(
|
||||
JavaOnlyArray.of("content-type", "multipart/form-data"));
|
||||
List<JavaOnlyArray> headers =
|
||||
Arrays.asList(JavaOnlyArray.of("content-type", "multipart/form-data"));
|
||||
|
||||
JavaOnlyMap body = new JavaOnlyMap();
|
||||
JavaOnlyArray formData = new JavaOnlyArray();
|
||||
@@ -609,9 +624,7 @@ public class NetworkingModuleTest {
|
||||
bodyPart.putString("string", "locale");
|
||||
bodyPart.putArray(
|
||||
"headers",
|
||||
JavaOnlyArray.from(
|
||||
Arrays.asList(
|
||||
JavaOnlyArray.of("content-disposition", "user"))));
|
||||
JavaOnlyArray.from(Arrays.asList(JavaOnlyArray.of("content-disposition", "user"))));
|
||||
formData.pushMap(bodyPart);
|
||||
|
||||
JavaOnlyMap imageBodyPart = new JavaOnlyMap();
|
||||
@@ -625,30 +638,31 @@ public class NetworkingModuleTest {
|
||||
formData.pushMap(imageBodyPart);
|
||||
|
||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Call callMock = mock(Call.class);
|
||||
return callMock;
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
networkingModule.sendRequest(
|
||||
"POST",
|
||||
"http://someurl/uploadFoo",
|
||||
0,
|
||||
JavaOnlyArray.from(headers),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"POST",
|
||||
"http://someurl/uploadFoo",
|
||||
0,
|
||||
JavaOnlyArray.from(headers),
|
||||
body,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
|
||||
// verify RequestBodyPart for image
|
||||
PowerMockito.verifyStatic(times(1));
|
||||
@@ -661,8 +675,8 @@ public class NetworkingModuleTest {
|
||||
verify(multipartBuilder).setType(MultipartBody.FORM);
|
||||
ArgumentCaptor<Headers> headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class);
|
||||
ArgumentCaptor<RequestBody> bodyArgumentCaptor = ArgumentCaptor.forClass(RequestBody.class);
|
||||
verify(multipartBuilder, times(2)).
|
||||
addPart(headersArgumentCaptor.capture(), bodyArgumentCaptor.capture());
|
||||
verify(multipartBuilder, times(2))
|
||||
.addPart(headersArgumentCaptor.capture(), bodyArgumentCaptor.capture());
|
||||
|
||||
List<Headers> bodyHeaders = headersArgumentCaptor.getAllValues();
|
||||
assertThat(bodyHeaders.size()).isEqualTo(2);
|
||||
@@ -688,31 +702,33 @@ public class NetworkingModuleTest {
|
||||
}
|
||||
|
||||
when(httpClient.cookieJar()).thenReturn(mock(CookieJarContainer.class));
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Request request = (Request) invocation.getArguments()[0];
|
||||
return calls[(Integer) request.tag() - 1];
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Request request = (Request) invocation.getArguments()[0];
|
||||
return calls[(Integer) request.tag() - 1];
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
networkingModule.initialize();
|
||||
|
||||
for (int idx = 0; idx < requests; idx++) {
|
||||
networkingModule.sendRequest(
|
||||
"GET",
|
||||
"http://somedomain/foo",
|
||||
idx + 1,
|
||||
JavaOnlyArray.of(),
|
||||
null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"GET",
|
||||
"http://somedomain/foo",
|
||||
idx + 1,
|
||||
JavaOnlyArray.of(),
|
||||
null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
}
|
||||
verify(httpClient, times(3)).newCall(any(Request.class));
|
||||
|
||||
@@ -739,30 +755,32 @@ public class NetworkingModuleTest {
|
||||
}
|
||||
|
||||
when(httpClient.cookieJar()).thenReturn(mock(CookieJarContainer.class));
|
||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Request request = (Request) invocation.getArguments()[0];
|
||||
return calls[(Integer) request.tag() - 1];
|
||||
}
|
||||
});
|
||||
when(httpClient.newCall(any(Request.class)))
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Request request = (Request) invocation.getArguments()[0];
|
||||
return calls[(Integer) request.tag() - 1];
|
||||
}
|
||||
});
|
||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||
when(clientBuilder.build()).thenReturn(httpClient);
|
||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||
NetworkingModule networkingModule =
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||
|
||||
for (int idx = 0; idx < requests; idx++) {
|
||||
networkingModule.sendRequest(
|
||||
"GET",
|
||||
"http://somedomain/foo",
|
||||
idx + 1,
|
||||
JavaOnlyArray.of(),
|
||||
null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
"GET",
|
||||
"http://somedomain/foo",
|
||||
idx + 1,
|
||||
JavaOnlyArray.of(),
|
||||
null,
|
||||
/* responseType */ "text",
|
||||
/* useIncrementalUpdates*/ true,
|
||||
/* timeout */ 0,
|
||||
/* withCredentials */ false);
|
||||
}
|
||||
verify(httpClient, times(3)).newCall(any(Request.class));
|
||||
|
||||
|
||||
+63
-62
@@ -1,74 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.network;
|
||||
|
||||
import com.facebook.react.common.StandardCharsets;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ProgressiveStringDecoderTest {
|
||||
|
||||
private static String TEST_DATA_1_BYTE = "Lorem ipsum dolor sit amet, ea ius viris laoreet gloriatur, ea enim illud mel. Ea eligendi erroribus inciderint sea, id nemore sensibus contentiones qui. Eos et nulla abhorreant, noluisse adipiscing reprehendunt an sit. Harum iriure meliore ne nec, clita semper voluptaria at sea. Ius civibus vituperata reprehendunt ut.\n" +
|
||||
"\n" +
|
||||
"Sed nisl postea maiorum ex, mea eros verterem ea. Ne usu brute debitis appareat. Ad quem reprimique dissentias duo. Sit an labitur eleifend, illud zril audiam nam ex, epicuri luptatum ne usu. Lorem mundi utinam vix ea.\n" +
|
||||
"\n" +
|
||||
"Te eam nominati qualisque. Ut praesent consetetur pro. Soleat vivendum vim ea. Altera dolores eam in. Eum at praesent complectitur. Nec ea inani definitiones, tantas vivendum mei an, mea an ubique omnium latine. Has mundi ocurreret ei, nam ea iuvaret gloriatur.\n" +
|
||||
"\n" +
|
||||
"Ad omnes malorum vim, no latine facilisi mel, dicant salutandi conclusionemque ei est. Nam cu partem alterum minimum. Et quo iriure deleniti accommodare, ad impetus perfecto liberavisse pri. Instructior necessitatibus ut mel, ex cum sumo atqui comprehensam, ei nullam oporteat sed. Ius meliore placerat cu.\n" +
|
||||
"\n" +
|
||||
"Eum in ferri nobis, eam eu verear facilisis referrentur. Veniam epicuri referrentur at nam. Vel congue diceret fabulas te, ei fabellas temporibus mei. Nemore corrumpit quo ex, et vis soluta reprehendunt. Et eos eripuit atomorum.\n" +
|
||||
"\n" +
|
||||
"Eum no novum tantas decore. Indoctum definiebas intellegam ut vel. Cu per ipsum graeco, in nam dico dolore, usu id ludus consulatu. Vis an clita commune, cu quot quaeque cum. In eos semper aperiri. Ne mea probo inermis, no vis audiam volutpat.\n" +
|
||||
"\n" +
|
||||
"Cu quaeque scaevola vis. Civibus commune scriptorem vim an, vim ea vocent petentium consequuntur, meis propriae invidunt eam ex. Pro et ponderum recusabo sapientem. Vel legere possim ornatus ne, saepe commodo scaevola an quo. An scaevola repudiandae sed. Eam ei veri nemore.\n" +
|
||||
"\n" +
|
||||
"Ullum deleniti cum at. An has soleat docendi, epicuri erroribus inciderint pro ea. Noluisse invidunt splendide quo in, eam odio invenire ea. Eu hinc definiebas scripserit duo, has cu equidem ponderum expetenda, eum vulputate intellegat id. Pri eu natum semper pertinax, ei vel inani aliquip habemus, sit an facer dicam. Et graeci abhorreant contentiones duo, et summo partiendo conclusionemque per.\n" +
|
||||
"\n" +
|
||||
"Sed ei etiam iudico abhorreant. Pri an regione fastidii, clita discere eu nec. Torquatos percipitur inciderint eos in, id per prompta blandit. Sit et epicuri deleniti. Per labores corpora no.\n" +
|
||||
"\n" +
|
||||
"Quodsi melius facilis pri ei, has adhuc recusabo reprimique ut. Laoreet definitionem cum cu, amet nonumes ut vis, qui ut sonet ancillae. Vim no doctus efficiantur, ancillae indoctum ex sea, vel eu fabulas volumus argumentum. Ex eum aeque commune placerat, nam choro tamquam luptatum et. Ne sea vero idque liberavisse";
|
||||
private static String TEST_DATA_1_BYTE =
|
||||
"Lorem ipsum dolor sit amet, ea ius viris laoreet gloriatur, ea enim illud mel. Ea eligendi erroribus inciderint sea, id nemore sensibus contentiones qui. Eos et nulla abhorreant, noluisse adipiscing reprehendunt an sit. Harum iriure meliore ne nec, clita semper voluptaria at sea. Ius civibus vituperata reprehendunt ut.\n"
|
||||
+ "\n"
|
||||
+ "Sed nisl postea maiorum ex, mea eros verterem ea. Ne usu brute debitis appareat. Ad quem reprimique dissentias duo. Sit an labitur eleifend, illud zril audiam nam ex, epicuri luptatum ne usu. Lorem mundi utinam vix ea.\n"
|
||||
+ "\n"
|
||||
+ "Te eam nominati qualisque. Ut praesent consetetur pro. Soleat vivendum vim ea. Altera dolores eam in. Eum at praesent complectitur. Nec ea inani definitiones, tantas vivendum mei an, mea an ubique omnium latine. Has mundi ocurreret ei, nam ea iuvaret gloriatur.\n"
|
||||
+ "\n"
|
||||
+ "Ad omnes malorum vim, no latine facilisi mel, dicant salutandi conclusionemque ei est. Nam cu partem alterum minimum. Et quo iriure deleniti accommodare, ad impetus perfecto liberavisse pri. Instructior necessitatibus ut mel, ex cum sumo atqui comprehensam, ei nullam oporteat sed. Ius meliore placerat cu.\n"
|
||||
+ "\n"
|
||||
+ "Eum in ferri nobis, eam eu verear facilisis referrentur. Veniam epicuri referrentur at nam. Vel congue diceret fabulas te, ei fabellas temporibus mei. Nemore corrumpit quo ex, et vis soluta reprehendunt. Et eos eripuit atomorum.\n"
|
||||
+ "\n"
|
||||
+ "Eum no novum tantas decore. Indoctum definiebas intellegam ut vel. Cu per ipsum graeco, in nam dico dolore, usu id ludus consulatu. Vis an clita commune, cu quot quaeque cum. In eos semper aperiri. Ne mea probo inermis, no vis audiam volutpat.\n"
|
||||
+ "\n"
|
||||
+ "Cu quaeque scaevola vis. Civibus commune scriptorem vim an, vim ea vocent petentium consequuntur, meis propriae invidunt eam ex. Pro et ponderum recusabo sapientem. Vel legere possim ornatus ne, saepe commodo scaevola an quo. An scaevola repudiandae sed. Eam ei veri nemore.\n"
|
||||
+ "\n"
|
||||
+ "Ullum deleniti cum at. An has soleat docendi, epicuri erroribus inciderint pro ea. Noluisse invidunt splendide quo in, eam odio invenire ea. Eu hinc definiebas scripserit duo, has cu equidem ponderum expetenda, eum vulputate intellegat id. Pri eu natum semper pertinax, ei vel inani aliquip habemus, sit an facer dicam. Et graeci abhorreant contentiones duo, et summo partiendo conclusionemque per.\n"
|
||||
+ "\n"
|
||||
+ "Sed ei etiam iudico abhorreant. Pri an regione fastidii, clita discere eu nec. Torquatos percipitur inciderint eos in, id per prompta blandit. Sit et epicuri deleniti. Per labores corpora no.\n"
|
||||
+ "\n"
|
||||
+ "Quodsi melius facilis pri ei, has adhuc recusabo reprimique ut. Laoreet definitionem cum cu, amet nonumes ut vis, qui ut sonet ancillae. Vim no doctus efficiantur, ancillae indoctum ex sea, vel eu fabulas volumus argumentum. Ex eum aeque commune placerat, nam choro tamquam luptatum et. Ne sea vero idque liberavisse";
|
||||
|
||||
private static String TEST_DATA_2_BYTES = "Лорем ипсум долор сит амет, доминг дисцере ад вих, велит игнота ратионибус мел цу. Не вирис малорум яуаеяуе хас, еу либрис доцтус хис. Моллис садипсцинг ан цум, семпер молестие репрехендунт усу те. Цасе аетерно оффендит ан еос. При ан толлит опортере оцурререт, ан яуот мутат трацтатос вих.\n" +
|
||||
"\n" +
|
||||
"Нец фалли харум ратионибус еа. Магна адмодум ат нам, яуи еа рецусабо мандамус, аццусам цонсеяуунтур цу хис. Импедит цотидиеяуе улламцорпер еа мел, усу ет долорес аргументум. Веро торяуатос ех нам, цибо либерависсе ест еи. Вис долор омниум сплендиде ад, велит рецусабо цонсететур иус цу.\n" +
|
||||
"\n" +
|
||||
"Еи дуо меис атоморум сигниферумяуе, аугуе аццусам мел ет. Ут ностро легендос хонестатис пер, ут яуас мовет сеа. Меа цу продессет аппеллантур. Вис еа яуод оффендит, дебет видерер ет нам.\n" +
|
||||
"\n" +
|
||||
"Еам еа дебитис иудицабит, не хас иллуд цивибус. Усу ет алии уллум утамур. Поссит цонституто те яуи, хас ет лаудем аудире, нам еи епицури салутанди. Лудус делицатиссими цум еу, либер адиписцинг еи нец. Ид ерипуит лобортис антиопам хис, санцтус елигенди неглегентур сед ут, вел сентентиае инструцтиор еи. Ан про унум яуалисяуе.\n" +
|
||||
"\n" +
|
||||
"Ат еррор алтера сит, пер еу яуот номинави. Пертинах репудиаре цум еу. Еа фуиссет антиопам вим, пробатус реферрентур ут иус. Еум ад модус утрояуе диспутандо.\n" +
|
||||
"\n" +
|
||||
"Ехерци бландит ут меа. Солет импедит сед ад. Дуо порро тимеам аудире не, алии ерант номинави цу нец, сит ферри веритус адиписци те. Те меи синт адверсариум, ад феугаит инвидунт луцилиус сед, дицунт нумяуам нам те. Еум дицант елеифенд цонсецтетуер ет, суммо вереар епицуреи не про. Не лудус сцрипта опортере вим, еи дуо идяуе алияуам сигниферумяуе. Цум еу лабитур инвенире, про ессе губергрен темпорибус еи, ад хис минимум пертинах.\n" +
|
||||
"\n" +
|
||||
"Дуо ад вери евертитур интеллегат, демоцритум еффициенди дуо ет. Нец но доценди демоцритум сцрипторем, витуперата цонституам нецесситатибус ут вим. Яуи виде санцтус мандамус ан, нонумес принципес вел ат, ех дуо инани нулла. Петентиум маиестатис еам ин, те ерант дебитис еурипидис вис. Но вел антиопам цотидиеяуе еффициантур, сеа еи нибх нонумы инцидеринт.\n" +
|
||||
"\n" +
|
||||
"Одио омнес но яуо, популо ноструд иус ад. Инани хонестатис но вис. Хис еу лудус партем персиус, пурто малис витуперата при ан, еи елаборарет ассуеверит вим. Цу бруте утинам тинцидунт вих, цум ад дицтас лобортис лаборамус. Нец хабемус рецусабо ат, ех фацилис денияуе ест. При те велит алияуам аццусамус, юсто утамур антиопам но нам.\n" +
|
||||
"\n" +
|
||||
"Про не еррем иудицо мелиоре, еи цибо ерудити санцтус хас. Яуод еяуидем еу вис, вих яуидам легимус ад, ид сеа солум легере мандамус. Аеяуе детрахит ех иус, суас вертерем еум цу. Еи вим алиа ехерци пхаедрум, хас не лаборес цоррумпит. Ат граеци сцрипта вим.\n" +
|
||||
"\n" +
|
||||
"Иус ат менандри персеяуерис. Про модус дицта еу, ин граеци доценди фиерент при, еи хас аугуе мандамус дефинитионем. Ет путент интерпретарис сит, перицула сентентиае ат ест. При ут сумо видит волуптатибус, нобис деленити еа.";
|
||||
private static String TEST_DATA_3_BYTES = "案のづよド捕毎エオ文疑ろめた今宮レ秋像とが供持属ょー真場中ホサヒ不箱らご著質ーぼンろ保6年読さ系蔵べるル緩参フシセタ鮮県フずッ歳民ナセ楽飲匹恒桜ぱ。要電ネソメ嘉負向ス援中ぜく界党フネ属平ぎ象越容レ書95争効99争効7翌テ売約わこよッ紙点発事9入そさ補綱のラず他亭匠ぞ。\n" +
|
||||
"\n" +
|
||||
"天レ供内ソ愛7読でぽせ回書ほごしな浅月企設潟せぐり裂個ホヌヤ局題制エ柏央ざぽ。外くにさ下格か終所あ硬当ワ着少選とけリへ康件終にぎ季規らおず給測トユテ考毎サトス事版にーご文8忙チ深暮タヲムラ度6応しぞぎぐ装速て続際ぞ発准揮包孤てい。制はたちき合南む乙甲ゅさと捕4球任条こでン頭広セスモウ月夜エス面陽ヨネ力京ウリ紙聞ト印2火映ラ基頭スフ点愛伎協ねド。\n" +
|
||||
"\n" +
|
||||
"属と共代みむもず以監すい者新ス田政家ヱス使校音刑トホ則上ゅぐ一未ヌ意40芸標んは学必強ゅ帝歯没牧具もか。58新イシレ正米ニユ負皇っぐせの必容キソタコ公3容ーつぶべ年然検ざ整賞ニチ注興ぐ放約えあ野夜磨やゃフよ。柳ソシアテ申1科ル舗紀深むぜ競供とび室全ハネ測高エラク権暮ヲクオト館暮ヌ黒杯クリぴぽ火竹ねる種4帰替やあい北問クルゃン登壌粉つどべ。";
|
||||
private static String TEST_DATA_2_BYTES =
|
||||
"Лорем ипсум долор сит амет, доминг дисцере ад вих, велит игнота ратионибус мел цу. Не вирис малорум яуаеяуе хас, еу либрис доцтус хис. Моллис садипсцинг ан цум, семпер молестие репрехендунт усу те. Цасе аетерно оффендит ан еос. При ан толлит опортере оцурререт, ан яуот мутат трацтатос вих.\n"
|
||||
+ "\n"
|
||||
+ "Нец фалли харум ратионибус еа. Магна адмодум ат нам, яуи еа рецусабо мандамус, аццусам цонсеяуунтур цу хис. Импедит цотидиеяуе улламцорпер еа мел, усу ет долорес аргументум. Веро торяуатос ех нам, цибо либерависсе ест еи. Вис долор омниум сплендиде ад, велит рецусабо цонсететур иус цу.\n"
|
||||
+ "\n"
|
||||
+ "Еи дуо меис атоморум сигниферумяуе, аугуе аццусам мел ет. Ут ностро легендос хонестатис пер, ут яуас мовет сеа. Меа цу продессет аппеллантур. Вис еа яуод оффендит, дебет видерер ет нам.\n"
|
||||
+ "\n"
|
||||
+ "Еам еа дебитис иудицабит, не хас иллуд цивибус. Усу ет алии уллум утамур. Поссит цонституто те яуи, хас ет лаудем аудире, нам еи епицури салутанди. Лудус делицатиссими цум еу, либер адиписцинг еи нец. Ид ерипуит лобортис антиопам хис, санцтус елигенди неглегентур сед ут, вел сентентиае инструцтиор еи. Ан про унум яуалисяуе.\n"
|
||||
+ "\n"
|
||||
+ "Ат еррор алтера сит, пер еу яуот номинави. Пертинах репудиаре цум еу. Еа фуиссет антиопам вим, пробатус реферрентур ут иус. Еум ад модус утрояуе диспутандо.\n"
|
||||
+ "\n"
|
||||
+ "Ехерци бландит ут меа. Солет импедит сед ад. Дуо порро тимеам аудире не, алии ерант номинави цу нец, сит ферри веритус адиписци те. Те меи синт адверсариум, ад феугаит инвидунт луцилиус сед, дицунт нумяуам нам те. Еум дицант елеифенд цонсецтетуер ет, суммо вереар епицуреи не про. Не лудус сцрипта опортере вим, еи дуо идяуе алияуам сигниферумяуе. Цум еу лабитур инвенире, про ессе губергрен темпорибус еи, ад хис минимум пертинах.\n"
|
||||
+ "\n"
|
||||
+ "Дуо ад вери евертитур интеллегат, демоцритум еффициенди дуо ет. Нец но доценди демоцритум сцрипторем, витуперата цонституам нецесситатибус ут вим. Яуи виде санцтус мандамус ан, нонумес принципес вел ат, ех дуо инани нулла. Петентиум маиестатис еам ин, те ерант дебитис еурипидис вис. Но вел антиопам цотидиеяуе еффициантур, сеа еи нибх нонумы инцидеринт.\n"
|
||||
+ "\n"
|
||||
+ "Одио омнес но яуо, популо ноструд иус ад. Инани хонестатис но вис. Хис еу лудус партем персиус, пурто малис витуперата при ан, еи елаборарет ассуеверит вим. Цу бруте утинам тинцидунт вих, цум ад дицтас лобортис лаборамус. Нец хабемус рецусабо ат, ех фацилис денияуе ест. При те велит алияуам аццусамус, юсто утамур антиопам но нам.\n"
|
||||
+ "\n"
|
||||
+ "Про не еррем иудицо мелиоре, еи цибо ерудити санцтус хас. Яуод еяуидем еу вис, вих яуидам легимус ад, ид сеа солум легере мандамус. Аеяуе детрахит ех иус, суас вертерем еум цу. Еи вим алиа ехерци пхаедрум, хас не лаборес цоррумпит. Ат граеци сцрипта вим.\n"
|
||||
+ "\n"
|
||||
+ "Иус ат менандри персеяуерис. Про модус дицта еу, ин граеци доценди фиерент при, еи хас аугуе мандамус дефинитионем. Ет путент интерпретарис сит, перицула сентентиае ат ест. При ут сумо видит волуптатибус, нобис деленити еа.";
|
||||
private static String TEST_DATA_3_BYTES =
|
||||
"案のづよド捕毎エオ文疑ろめた今宮レ秋像とが供持属ょー真場中ホサヒ不箱らご著質ーぼンろ保6年読さ系蔵べるル緩参フシセタ鮮県フずッ歳民ナセ楽飲匹恒桜ぱ。要電ネソメ嘉負向ス援中ぜく界党フネ属平ぎ象越容レ書95争効99争効7翌テ売約わこよッ紙点発事9入そさ補綱のラず他亭匠ぞ。\n"
|
||||
+ "\n"
|
||||
+ "天レ供内ソ愛7読でぽせ回書ほごしな浅月企設潟せぐり裂個ホヌヤ局題制エ柏央ざぽ。外くにさ下格か終所あ硬当ワ着少選とけリへ康件終にぎ季規らおず給測トユテ考毎サトス事版にーご文8忙チ深暮タヲムラ度6応しぞぎぐ装速て続際ぞ発准揮包孤てい。制はたちき合南む乙甲ゅさと捕4球任条こでン頭広セスモウ月夜エス面陽ヨネ力京ウリ紙聞ト印2火映ラ基頭スフ点愛伎協ねド。\n"
|
||||
+ "\n"
|
||||
+ "属と共代みむもず以監すい者新ス田政家ヱス使校音刑トホ則上ゅぐ一未ヌ意40芸標んは学必強ゅ帝歯没牧具もか。58新イシレ正米ニユ負皇っぐせの必容キソタコ公3容ーつぶべ年然検ざ整賞ニチ注興ぐ放約えあ野夜磨やゃフよ。柳ソシアテ申1科ル舗紀深むぜ競供とび室全ハネ測高エラク権暮ヲクオト館暮ヌ黒杯クリぴぽ火竹ねる種4帰替やあい北問クルゃン登壌粉つどべ。";
|
||||
|
||||
private static final String TEST_DATA_4_BYTES ="\uD800\uDE55\uD800\uDE55\uD800\uDE55 \uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55" +
|
||||
"\uD800\uDE55\uD800\uDE55\uD800\uDE55 \uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80" +
|
||||
"\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80" +
|
||||
"\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80" +
|
||||
"\uD800\uDE80\uD800\uDE80\uD800\uDE80";
|
||||
private static final String TEST_DATA_4_BYTES =
|
||||
"\uD800\uDE55\uD800\uDE55\uD800\uDE55 \uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55"
|
||||
+ "\uD800\uDE55\uD800\uDE55\uD800\uDE55 \uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80"
|
||||
+ "\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80"
|
||||
+ "\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE55\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80\uD800\uDE80"
|
||||
+ "\uD800\uDE80\uD800\uDE80\uD800\uDE80";
|
||||
|
||||
@Test
|
||||
public void testUTF8SingleByteSymbols() {
|
||||
@@ -91,23 +92,23 @@ public class ProgressiveStringDecoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTF16LEStandard() throws Exception {
|
||||
public void testUTF16LEStandard() throws Exception {
|
||||
chunkString(TEST_DATA_3_BYTES, StandardCharsets.UTF_16LE, 47);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTF16LESurrogates() throws Exception {
|
||||
public void testUTF16LESurrogates() throws Exception {
|
||||
// 4 bytes UTF-8 symbols are encoded as two 2 byte surrogate symbols in UTF-16
|
||||
chunkString(TEST_DATA_4_BYTES, StandardCharsets.UTF_16LE, 47);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTF16BEStandard() throws Exception {
|
||||
public void testUTF16BEStandard() throws Exception {
|
||||
chunkString(TEST_DATA_3_BYTES, StandardCharsets.UTF_16BE, 47);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTF16BESurrogates() throws Exception {
|
||||
public void testUTF16BESurrogates() throws Exception {
|
||||
// 4 bytes UTF-8 symbols are encoded as two 2 byte surrogate symbols in UTF-16
|
||||
chunkString(TEST_DATA_4_BYTES, StandardCharsets.UTF_16BE, 47);
|
||||
}
|
||||
@@ -119,15 +120,15 @@ public class ProgressiveStringDecoderTest {
|
||||
}
|
||||
|
||||
private void chunkString(String originalString, Charset charset, int chunkSize) {
|
||||
byte data [] = originalString.getBytes(charset);
|
||||
byte data[] = originalString.getBytes(charset);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
ProgressiveStringDecoder collector = new ProgressiveStringDecoder(charset);
|
||||
byte[] buffer = new byte[chunkSize];
|
||||
for (int i = 0; i < data.length; i+= chunkSize) {
|
||||
for (int i = 0; i < data.length; i += chunkSize) {
|
||||
int bytesRead = Math.min(chunkSize, data.length - i);
|
||||
System.arraycopy(data, i, buffer, 0, bytesRead );
|
||||
builder.append(collector.decodeNext(buffer, bytesRead ));
|
||||
System.arraycopy(data, i, buffer, 0, bytesRead);
|
||||
builder.append(collector.decodeNext(buffer, bytesRead));
|
||||
}
|
||||
|
||||
String actualString = builder.toString();
|
||||
|
||||
+13
-32
@@ -1,40 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.network;
|
||||
|
||||
import com.facebook.react.modules.network.ReactCookieJarContainer;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.CookieJar;
|
||||
import okhttp3.HttpUrl;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link NetworkingModule}.
|
||||
*/
|
||||
@PrepareForTest({
|
||||
ReactCookieJarContainer.class
|
||||
})
|
||||
/** Tests for {@link NetworkingModule}. */
|
||||
@PrepareForTest({ReactCookieJarContainer.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
|
||||
public class ReactCookieJarContainerTest {
|
||||
|
||||
@Test
|
||||
@@ -57,12 +48,7 @@ public class ReactCookieJarContainerTest {
|
||||
CookieJar cookieJar = mock(CookieJar.class);
|
||||
jarContainer.setCookieJar(cookieJar);
|
||||
List<Cookie> cookies = new ArrayList<>();
|
||||
cookies.add(new Cookie.Builder()
|
||||
.name("valid")
|
||||
.value("valid value")
|
||||
.domain("domain")
|
||||
.build()
|
||||
);
|
||||
cookies.add(new Cookie.Builder().name("valid").value("valid value").domain("domain").build());
|
||||
when(cookieJar.loadForRequest(any(HttpUrl.class))).thenReturn(cookies);
|
||||
assertThat(jarContainer.loadForRequest(any(HttpUrl.class)).size()).isEqualTo(1);
|
||||
}
|
||||
@@ -73,12 +59,7 @@ public class ReactCookieJarContainerTest {
|
||||
CookieJar cookieJar = mock(CookieJar.class);
|
||||
jarContainer.setCookieJar(cookieJar);
|
||||
List<Cookie> cookies = new ArrayList<>();
|
||||
cookies.add(new Cookie.Builder()
|
||||
.name("valid")
|
||||
.value("înválíd välūė")
|
||||
.domain("domain")
|
||||
.build()
|
||||
);
|
||||
cookies.add(new Cookie.Builder().name("valid").value("înválíd välūė").domain("domain").build());
|
||||
when(cookieJar.loadForRequest(any(HttpUrl.class))).thenReturn(cookies);
|
||||
assertThat(jarContainer.loadForRequest(any(HttpUrl.class)).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.share;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -33,12 +35,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.internal.ShadowExtractor;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@PrepareForTest({Arguments.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
@@ -47,20 +43,19 @@ public class ShareModuleTest {
|
||||
private Activity mActivity;
|
||||
private ShareModule mShareModule;
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Before
|
||||
public void prepareModules() throws Exception {
|
||||
PowerMockito.mockStatic(Arguments.class);
|
||||
Mockito
|
||||
.when(Arguments.createMap())
|
||||
.thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
Mockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
|
||||
mShareModule = new ShareModule(ReactTestHelper.createCatalystContextForTest());
|
||||
}
|
||||
@@ -86,33 +81,17 @@ public class ShareModuleTest {
|
||||
mShareModule.share(content, dialogTitle, promise);
|
||||
|
||||
final Intent chooserIntent =
|
||||
((ShadowApplication) ShadowExtractor.extract(RuntimeEnvironment.application)).getNextStartedActivity();
|
||||
((ShadowApplication) ShadowExtractor.extract(RuntimeEnvironment.application))
|
||||
.getNextStartedActivity();
|
||||
assertNotNull("Dialog was not displayed", chooserIntent);
|
||||
assertEquals(Intent.ACTION_CHOOSER, chooserIntent.getAction());
|
||||
assertEquals(
|
||||
dialogTitle,
|
||||
chooserIntent
|
||||
.getExtras()
|
||||
.get(Intent.EXTRA_TITLE)
|
||||
);
|
||||
assertEquals(dialogTitle, chooserIntent.getExtras().get(Intent.EXTRA_TITLE));
|
||||
|
||||
final Intent contentIntent = (Intent) chooserIntent
|
||||
.getExtras()
|
||||
.get(Intent.EXTRA_INTENT);
|
||||
final Intent contentIntent = (Intent) chooserIntent.getExtras().get(Intent.EXTRA_INTENT);
|
||||
assertNotNull("Intent was not built correctly", contentIntent);
|
||||
assertEquals(Intent.ACTION_SEND, contentIntent.getAction());
|
||||
assertEquals(
|
||||
title,
|
||||
contentIntent
|
||||
.getExtras()
|
||||
.get(Intent.EXTRA_SUBJECT)
|
||||
);
|
||||
assertEquals(
|
||||
message,
|
||||
contentIntent
|
||||
.getExtras()
|
||||
.get(Intent.EXTRA_TEXT)
|
||||
);
|
||||
assertEquals(title, contentIntent.getExtras().get(Intent.EXTRA_SUBJECT));
|
||||
assertEquals(message, contentIntent.getExtras().get(Intent.EXTRA_TEXT));
|
||||
|
||||
assertEquals(1, promise.getResolved());
|
||||
}
|
||||
@@ -129,7 +108,7 @@ public class ShareModuleTest {
|
||||
assertEquals(ShareModule.ERROR_INVALID_CONTENT, promise.getErrorCode());
|
||||
}
|
||||
|
||||
final static class SimplePromise implements Promise {
|
||||
static final class SimplePromise implements Promise {
|
||||
private static final String ERROR_DEFAULT_CODE = "EUNSPECIFIED";
|
||||
private static final String ERROR_DEFAULT_MESSAGE = "Error not specified.";
|
||||
|
||||
@@ -167,42 +146,42 @@ public class ShareModuleTest {
|
||||
|
||||
@Override
|
||||
public void reject(String code, String message) {
|
||||
reject(code, message, /*Throwable*/null, /*WritableMap*/null);
|
||||
reject(code, message, /*Throwable*/ null, /*WritableMap*/ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(String code, Throwable throwable) {
|
||||
reject(code, /*Message*/null, throwable, /*WritableMap*/null);
|
||||
reject(code, /*Message*/ null, throwable, /*WritableMap*/ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(String code, String message, Throwable throwable) {
|
||||
reject(code, message, throwable, /*WritableMap*/null);
|
||||
reject(code, message, throwable, /*WritableMap*/ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(Throwable throwable) {
|
||||
reject(/*Code*/null, /*Message*/null, throwable, /*WritableMap*/null);
|
||||
reject(/*Code*/ null, /*Message*/ null, throwable, /*WritableMap*/ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(Throwable throwable, WritableMap userInfo) {
|
||||
reject(/*Code*/null, /*Message*/null, throwable, userInfo);
|
||||
reject(/*Code*/ null, /*Message*/ null, throwable, userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(String code, @Nonnull WritableMap userInfo) {
|
||||
reject(code, /*Message*/null, /*Throwable*/null, userInfo);
|
||||
reject(code, /*Message*/ null, /*Throwable*/ null, userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(String code, Throwable throwable, WritableMap userInfo) {
|
||||
reject(code, /*Message*/null, throwable, userInfo);
|
||||
reject(code, /*Message*/ null, throwable, userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(String code, String message, @Nonnull WritableMap userInfo) {
|
||||
reject(code, message, /*Throwable*/null, userInfo);
|
||||
reject(code, message, /*Throwable*/ null, userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,8 +189,7 @@ public class ShareModuleTest {
|
||||
String code,
|
||||
String message,
|
||||
@Nullable Throwable throwable,
|
||||
@Nullable WritableMap userInfo
|
||||
) {
|
||||
@Nullable WritableMap userInfo) {
|
||||
mRejected++;
|
||||
|
||||
if (code == null) {
|
||||
@@ -232,7 +210,7 @@ public class ShareModuleTest {
|
||||
@Override
|
||||
@Deprecated
|
||||
public void reject(String message) {
|
||||
reject(/*Code*/null, message, /*Throwable*/null, /*WritableMap*/null);
|
||||
reject(/*Code*/ null, message, /*Throwable*/ null, /*WritableMap*/ null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-48
@@ -1,32 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.storage;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.AsyncTask;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.GuardedAsyncTask;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.modules.storage.AsyncStorageModule;
|
||||
import com.facebook.react.modules.storage.ReactDatabaseSupplier;
|
||||
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.After;
|
||||
@@ -34,26 +24,20 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.mockito.verification.VerificationMode;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.concurrent.RoboExecutorService;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link AsyncStorageModule}.
|
||||
*/
|
||||
/** Tests for {@link com.facebook.react.modules.storage.AsyncStorageModule}. */
|
||||
@PrepareForTest({Arguments.class})
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*", "org.json.*"})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -62,33 +46,33 @@ public class AsyncStorageModuleTest {
|
||||
private AsyncStorageModule mStorage;
|
||||
private JavaOnlyArray mEmptyArray;
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Before
|
||||
public void prepareModules() {
|
||||
PowerMockito.mockStatic(Arguments.class);
|
||||
Mockito.when(Arguments.createArray()).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
Mockito.when(Arguments.createArray())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
|
||||
Mockito.when(Arguments.createMap()).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
Mockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
|
||||
// don't use Robolectric before initializing mocks
|
||||
mStorage = new AsyncStorageModule(
|
||||
ReactTestHelper.createCatalystContextForTest(),
|
||||
new RoboExecutorService()
|
||||
);
|
||||
mStorage =
|
||||
new AsyncStorageModule(
|
||||
ReactTestHelper.createCatalystContextForTest(), new RoboExecutorService());
|
||||
mEmptyArray = new JavaOnlyArray();
|
||||
}
|
||||
|
||||
@@ -276,7 +260,8 @@ public class AsyncStorageModuleTest {
|
||||
keys.pushString("key" + i);
|
||||
}
|
||||
mStorage.multiGet(
|
||||
keys, new Callback() {
|
||||
keys,
|
||||
new Callback() {
|
||||
@Override
|
||||
public void invoke(Object... args) {
|
||||
assertThat(args.length).isEqualTo(2);
|
||||
|
||||
+39
-38
@@ -1,23 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.modules.timing;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.common.SystemClock;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.modules.core.ChoreographerCompat;
|
||||
import com.facebook.react.modules.core.JSTimers;
|
||||
import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.modules.core.Timing;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -25,16 +25,12 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link Timing}.
|
||||
*/
|
||||
/** Tests for {@link Timing}. */
|
||||
// DISABLED, BROKEN https://circleci.com/gh/facebook/react-native/12068
|
||||
// t=13905097
|
||||
@PrepareForTest({Arguments.class, SystemClock.class, ReactChoreographer.class})
|
||||
@@ -51,19 +47,19 @@ public class TimingModuleTest {
|
||||
private long mCurrentTimeNs;
|
||||
private JSTimers mJSTimersMock;
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Before
|
||||
public void prepareModules() {
|
||||
PowerMockito.mockStatic(Arguments.class);
|
||||
when(Arguments.createArray()).thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
when(Arguments.createArray())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
|
||||
PowerMockito.mockStatic(SystemClock.class);
|
||||
when(SystemClock.uptimeMillis()).thenReturn(mCurrentTimeNs / 1000000);
|
||||
@@ -83,35 +79,40 @@ public class TimingModuleTest {
|
||||
mIdlePostFrameCallbackHandler = new PostFrameIdleCallbackHandler();
|
||||
|
||||
doAnswer(mPostFrameCallbackHandler)
|
||||
.when(mReactChoreographerMock)
|
||||
.postFrameCallback(
|
||||
eq(ReactChoreographer.CallbackType.TIMERS_EVENTS),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
.when(mReactChoreographerMock)
|
||||
.postFrameCallback(
|
||||
eq(ReactChoreographer.CallbackType.TIMERS_EVENTS),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
|
||||
doAnswer(mIdlePostFrameCallbackHandler)
|
||||
.when(mReactChoreographerMock)
|
||||
.postFrameCallback(
|
||||
eq(ReactChoreographer.CallbackType.IDLE_EVENT),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
.when(mReactChoreographerMock)
|
||||
.postFrameCallback(
|
||||
eq(ReactChoreographer.CallbackType.IDLE_EVENT),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
|
||||
mTiming = new Timing(reactContext, mock(DevSupportManager.class));
|
||||
mJSTimersMock = mock(JSTimers.class);
|
||||
when(reactContext.getJSModule(JSTimers.class)).thenReturn(mJSTimersMock);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
((Runnable) invocation.getArguments()[0]).run();
|
||||
return null;
|
||||
}
|
||||
}).when(reactContext).runOnJSQueueThread(any(Runnable.class));
|
||||
doAnswer(
|
||||
new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
((Runnable) invocation.getArguments()[0]).run();
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.when(reactContext)
|
||||
.runOnJSQueueThread(any(Runnable.class));
|
||||
|
||||
mTiming.initialize();
|
||||
}
|
||||
|
||||
private void stepChoreographerFrame() {
|
||||
ChoreographerCompat.FrameCallback callback = mPostFrameCallbackHandler.getAndResetFrameCallback();
|
||||
ChoreographerCompat.FrameCallback idleCallback = mIdlePostFrameCallbackHandler.getAndResetFrameCallback();
|
||||
ChoreographerCompat.FrameCallback callback =
|
||||
mPostFrameCallbackHandler.getAndResetFrameCallback();
|
||||
ChoreographerCompat.FrameCallback idleCallback =
|
||||
mIdlePostFrameCallbackHandler.getAndResetFrameCallback();
|
||||
|
||||
mCurrentTimeNs += FRAME_TIME_NS;
|
||||
when(SystemClock.uptimeMillis()).thenReturn(mCurrentTimeNs / 1000000);
|
||||
|
||||
+29
-25
@@ -1,33 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.packagerconnection;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import com.facebook.react.packagerconnection.ReconnectingWebSocket.ConnectionCallback;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import okio.ByteString;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class JSPackagerClientTest {
|
||||
private static Map<String, RequestHandler> createRH(
|
||||
String action, RequestHandler handler) {
|
||||
Map<String, RequestHandler> m =
|
||||
new HashMap<String, RequestHandler>();
|
||||
private static Map<String, RequestHandler> createRH(String action, RequestHandler handler) {
|
||||
Map<String, RequestHandler> m = new HashMap<String, RequestHandler>();
|
||||
m.put(action, handler);
|
||||
return m;
|
||||
}
|
||||
@@ -44,7 +38,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_ShouldTriggerNotification() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage("{\"version\": 2, \"method\": \"methodValue\", \"params\": \"paramsValue\"}");
|
||||
verify(handler).onNotification(eq("paramsValue"));
|
||||
@@ -54,9 +49,11 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_ShouldTriggerRequest() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage("{\"version\": 2, \"id\": \"idValue\", \"method\": \"methodValue\", \"params\": \"paramsValue\"}");
|
||||
client.onMessage(
|
||||
"{\"version\": 2, \"id\": \"idValue\", \"method\": \"methodValue\", \"params\": \"paramsValue\"}");
|
||||
verify(handler, never()).onNotification(any());
|
||||
verify(handler).onRequest(eq("paramsValue"), any(Responder.class));
|
||||
}
|
||||
@@ -64,7 +61,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_WithoutParams_ShouldTriggerNotification() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage("{\"version\": 2, \"method\": \"methodValue\"}");
|
||||
verify(handler).onNotification(eq(null));
|
||||
@@ -74,7 +72,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_WithInvalidContentType_ShouldNotTriggerCallback() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage(ByteString.encodeUtf8("{\"version\": 2, \"method\": \"methodValue\"}"));
|
||||
verify(handler, never()).onNotification(any());
|
||||
@@ -84,7 +83,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_WithoutMethod_ShouldNotTriggerCallback() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage("{\"version\": 2}");
|
||||
verify(handler, never()).onNotification(any());
|
||||
@@ -94,7 +94,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_With_Null_Action_ShouldNotTriggerCallback() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage("{\"version\": 2, \"method\": null}");
|
||||
verify(handler, never()).onNotification(any());
|
||||
@@ -104,7 +105,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_WithInvalidMethod_ShouldNotTriggerCallback() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage(ByteString.EMPTY);
|
||||
verify(handler, never()).onNotification(any());
|
||||
@@ -114,7 +116,8 @@ public class JSPackagerClientTest {
|
||||
@Test
|
||||
public void test_onMessage_WrongVersion_ShouldNotTriggerCallback() throws IOException {
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||
|
||||
client.onMessage("{\"version\": 1, \"method\": \"methodValue\"}");
|
||||
verify(handler, never()).onNotification(any());
|
||||
@@ -126,7 +129,8 @@ public class JSPackagerClientTest {
|
||||
ConnectionCallback connectionHandler = mock(ConnectionCallback.class);
|
||||
RequestHandler handler = mock(RequestHandler.class);
|
||||
final JSPackagerClient client =
|
||||
new JSPackagerClient("test_client", mSettings, new HashMap<String,RequestHandler>(), connectionHandler);
|
||||
new JSPackagerClient(
|
||||
"test_client", mSettings, new HashMap<String, RequestHandler>(), connectionHandler);
|
||||
|
||||
client.close();
|
||||
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import com.facebook.react.R;
|
||||
import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole;
|
||||
import com.facebook.react.views.view.ReactViewGroup;
|
||||
import com.facebook.react.views.view.ReactViewManager;
|
||||
import com.facebook.react.R;
|
||||
import java.util.Locale;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BaseViewManagerTest {
|
||||
|
||||
+104
-123
@@ -1,33 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.facebook.yoga.YogaAlign;
|
||||
import com.facebook.yoga.YogaConstants;
|
||||
import com.facebook.yoga.YogaFlexDirection;
|
||||
import com.facebook.yoga.YogaJustify;
|
||||
import com.facebook.yoga.YogaPositionType;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyFloat;
|
||||
@@ -40,13 +18,31 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.yoga.YogaAlign;
|
||||
import com.facebook.yoga.YogaConstants;
|
||||
import com.facebook.yoga.YogaFlexDirection;
|
||||
import com.facebook.yoga.YogaJustify;
|
||||
import com.facebook.yoga.YogaPositionType;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@PrepareForTest({PixelUtil.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class LayoutPropertyApplicatorTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -67,16 +63,8 @@ public class LayoutPropertyApplicatorTest {
|
||||
@Test
|
||||
public void testDimensions() {
|
||||
LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode());
|
||||
ReactStylesDiffMap map = spy(
|
||||
buildStyles(
|
||||
"width",
|
||||
10.0,
|
||||
"height",
|
||||
10.0,
|
||||
"left",
|
||||
10.0,
|
||||
"top",
|
||||
10.0));
|
||||
ReactStylesDiffMap map =
|
||||
spy(buildStyles("width", 10.0, "height", 10.0, "left", 10.0, "top", 10.0));
|
||||
|
||||
reactShadowNode.updateProperties(map);
|
||||
verify(reactShadowNode).setStyleWidth(anyFloat());
|
||||
@@ -122,13 +110,7 @@ public class LayoutPropertyApplicatorTest {
|
||||
@Test
|
||||
public void testPosition() {
|
||||
LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode());
|
||||
ReactStylesDiffMap map = spy(buildStyles(
|
||||
"position",
|
||||
"absolute",
|
||||
"bottom",
|
||||
10.0,
|
||||
"right",
|
||||
5.0));
|
||||
ReactStylesDiffMap map = spy(buildStyles("position", "absolute", "bottom", 10.0, "right", 5.0));
|
||||
|
||||
reactShadowNode.updateProperties(map);
|
||||
verify(reactShadowNode).setPosition(eq(Spacing.BOTTOM), anyFloat());
|
||||
@@ -285,17 +267,18 @@ public class LayoutPropertyApplicatorTest {
|
||||
@Test
|
||||
public void testEnumerations() {
|
||||
LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode());
|
||||
ReactStylesDiffMap map = buildStyles(
|
||||
"flexDirection",
|
||||
"column",
|
||||
"alignSelf",
|
||||
"stretch",
|
||||
"alignItems",
|
||||
"center",
|
||||
"justifyContent",
|
||||
"space_between",
|
||||
"position",
|
||||
"relative");
|
||||
ReactStylesDiffMap map =
|
||||
buildStyles(
|
||||
"flexDirection",
|
||||
"column",
|
||||
"alignSelf",
|
||||
"stretch",
|
||||
"alignItems",
|
||||
"center",
|
||||
"justifyContent",
|
||||
"space_between",
|
||||
"position",
|
||||
"relative");
|
||||
|
||||
reactShadowNode.updateProperties(map);
|
||||
verify(reactShadowNode).setFlexDirection(YogaFlexDirection.COLUMN);
|
||||
@@ -322,33 +305,34 @@ public class LayoutPropertyApplicatorTest {
|
||||
DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics);
|
||||
|
||||
LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode());
|
||||
ReactStylesDiffMap map = buildStyles(
|
||||
"width",
|
||||
10.0,
|
||||
"height",
|
||||
10.0,
|
||||
"left",
|
||||
10.0,
|
||||
"top",
|
||||
10.0,
|
||||
"flex",
|
||||
1.0,
|
||||
"padding",
|
||||
10.0,
|
||||
"marginLeft",
|
||||
10.0,
|
||||
"borderTopWidth",
|
||||
10.0,
|
||||
"flexDirection",
|
||||
"row",
|
||||
"alignSelf",
|
||||
"stretch",
|
||||
"alignItems",
|
||||
"center",
|
||||
"justifyContent",
|
||||
"space_between",
|
||||
"position",
|
||||
"absolute");
|
||||
ReactStylesDiffMap map =
|
||||
buildStyles(
|
||||
"width",
|
||||
10.0,
|
||||
"height",
|
||||
10.0,
|
||||
"left",
|
||||
10.0,
|
||||
"top",
|
||||
10.0,
|
||||
"flex",
|
||||
1.0,
|
||||
"padding",
|
||||
10.0,
|
||||
"marginLeft",
|
||||
10.0,
|
||||
"borderTopWidth",
|
||||
10.0,
|
||||
"flexDirection",
|
||||
"row",
|
||||
"alignSelf",
|
||||
"stretch",
|
||||
"alignItems",
|
||||
"center",
|
||||
"justifyContent",
|
||||
"space_between",
|
||||
"position",
|
||||
"absolute");
|
||||
|
||||
reactShadowNode.updateProperties(map);
|
||||
verify(reactShadowNode).setStyleWidth(10.f);
|
||||
@@ -365,33 +349,34 @@ public class LayoutPropertyApplicatorTest {
|
||||
verify(reactShadowNode).setJustifyContent(YogaJustify.SPACE_BETWEEN);
|
||||
verify(reactShadowNode).setPositionType(YogaPositionType.ABSOLUTE);
|
||||
|
||||
map = buildStyles(
|
||||
"width",
|
||||
null,
|
||||
"height",
|
||||
null,
|
||||
"left",
|
||||
null,
|
||||
"top",
|
||||
null,
|
||||
"flex",
|
||||
null,
|
||||
"padding",
|
||||
null,
|
||||
"marginLeft",
|
||||
null,
|
||||
"borderTopWidth",
|
||||
null,
|
||||
"flexDirection",
|
||||
null,
|
||||
"alignSelf",
|
||||
null,
|
||||
"alignItems",
|
||||
null,
|
||||
"justifyContent",
|
||||
null,
|
||||
"position",
|
||||
null);
|
||||
map =
|
||||
buildStyles(
|
||||
"width",
|
||||
null,
|
||||
"height",
|
||||
null,
|
||||
"left",
|
||||
null,
|
||||
"top",
|
||||
null,
|
||||
"flex",
|
||||
null,
|
||||
"padding",
|
||||
null,
|
||||
"marginLeft",
|
||||
null,
|
||||
"borderTopWidth",
|
||||
null,
|
||||
"flexDirection",
|
||||
null,
|
||||
"alignSelf",
|
||||
null,
|
||||
"alignItems",
|
||||
null,
|
||||
"justifyContent",
|
||||
null,
|
||||
"position",
|
||||
null);
|
||||
|
||||
reset(reactShadowNode);
|
||||
reactShadowNode.updateProperties(map);
|
||||
@@ -413,14 +398,15 @@ public class LayoutPropertyApplicatorTest {
|
||||
@Test
|
||||
public void testSettingDefaultStyleValues() {
|
||||
mockStatic(PixelUtil.class);
|
||||
when(PixelUtil.toPixelFromDIP(anyFloat())).thenAnswer(
|
||||
new Answer() {
|
||||
@Override
|
||||
public Float answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
return (Float) args[0];
|
||||
}
|
||||
});
|
||||
when(PixelUtil.toPixelFromDIP(anyFloat()))
|
||||
.thenAnswer(
|
||||
new Answer() {
|
||||
@Override
|
||||
public Float answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
return (Float) args[0];
|
||||
}
|
||||
});
|
||||
|
||||
LayoutShadowNode[] nodes = new LayoutShadowNode[7];
|
||||
for (int idx = 0; idx < nodes.length; idx++) {
|
||||
@@ -437,13 +423,8 @@ public class LayoutPropertyApplicatorTest {
|
||||
mapNodes[2] = buildStyles("paddingLeft", 10.0, "paddingVertical", 5.0);
|
||||
mapNodes[3] = buildStyles("paddingBottom", 10.0, "paddingHorizontal", 5.0);
|
||||
mapNodes[4] = buildStyles("padding", null, "paddingTop", 5.0);
|
||||
mapNodes[5] = buildStyles(
|
||||
"paddingRight",
|
||||
10.0,
|
||||
"paddingHorizontal",
|
||||
null,
|
||||
"paddingVertical",
|
||||
7.0);
|
||||
mapNodes[5] =
|
||||
buildStyles("paddingRight", 10.0, "paddingHorizontal", null, "paddingVertical", 7.0);
|
||||
mapNodes[6] = buildStyles("margin", 5.0);
|
||||
|
||||
for (int idx = 0; idx < nodes.length; idx++) {
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link MatrixMathHelper}
|
||||
*/
|
||||
/** Test for {@link MatrixMathHelper} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MatrixMathHelperTest {
|
||||
|
||||
private void verifyZRotatedMatrix(double degrees, double rotX, double rotY, double rotZ) {
|
||||
MatrixMathHelper.MatrixDecompositionContext ctx =
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
double[] matrix = createRotateZ(degreesToRadians(degrees));
|
||||
MatrixMathHelper.decomposeMatrix(matrix, ctx);
|
||||
assertThat(ctx.rotationDegrees).containsSequence(rotX, rotY, rotZ);
|
||||
@@ -29,7 +26,7 @@ public class MatrixMathHelperTest {
|
||||
|
||||
private void verifyYRotatedMatrix(double degrees, double rotX, double rotY, double rotZ) {
|
||||
MatrixMathHelper.MatrixDecompositionContext ctx =
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
double[] matrix = createRotateY(degreesToRadians(degrees));
|
||||
MatrixMathHelper.decomposeMatrix(matrix, ctx);
|
||||
assertThat(ctx.rotationDegrees).containsSequence(rotX, rotY, rotZ);
|
||||
@@ -37,15 +34,16 @@ public class MatrixMathHelperTest {
|
||||
|
||||
private void verifyXRotatedMatrix(double degrees, double rotX, double rotY, double rotZ) {
|
||||
MatrixMathHelper.MatrixDecompositionContext ctx =
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
double[] matrix = createRotateX(degreesToRadians(degrees));
|
||||
MatrixMathHelper.decomposeMatrix(matrix, ctx);
|
||||
assertThat(ctx.rotationDegrees).containsSequence(rotX, rotY, rotZ);
|
||||
}
|
||||
|
||||
private void verifyRotatedMatrix(double degreesX, double degreesY, double degreesZ, double rotX, double rotY, double rotZ) {
|
||||
private void verifyRotatedMatrix(
|
||||
double degreesX, double degreesY, double degreesZ, double rotX, double rotY, double rotZ) {
|
||||
MatrixMathHelper.MatrixDecompositionContext ctx =
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
double[] matrixX = createRotateX(degreesToRadians(degreesX));
|
||||
double[] matrixY = createRotateY(degreesToRadians(degreesY));
|
||||
double[] matrixZ = createRotateZ(degreesToRadians(degreesZ));
|
||||
@@ -61,15 +59,14 @@ public class MatrixMathHelperTest {
|
||||
public void testDecomposing4x4MatrixToProduceAccurateZaxisAngles() {
|
||||
|
||||
MatrixMathHelper.MatrixDecompositionContext ctx =
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
new MatrixMathHelper.MatrixDecompositionContext();
|
||||
|
||||
MatrixMathHelper.decomposeMatrix(
|
||||
new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
|
||||
ctx);
|
||||
new double[] {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, ctx);
|
||||
|
||||
assertThat(ctx.rotationDegrees).containsSequence(0d, 0d, 0d);
|
||||
|
||||
double[] angles = new double[]{30, 45, 60, 75, 90, 100, 115, 120, 133, 167};
|
||||
double[] angles = new double[] {30, 45, 60, 75, 90, 100, 115, 120, 133, 167};
|
||||
for (double angle : angles) {
|
||||
verifyZRotatedMatrix(angle, 0d, 0d, angle);
|
||||
verifyZRotatedMatrix(-angle, 0d, 0d, -angle);
|
||||
@@ -103,7 +100,7 @@ public class MatrixMathHelperTest {
|
||||
|
||||
@Test
|
||||
public void testDecomposing4x4MatrixToProduceAccurateYaxisAngles() {
|
||||
double[] angles = new double[]{30, 45, 60, 75, 90};
|
||||
double[] angles = new double[] {30, 45, 60, 75, 90};
|
||||
for (double angle : angles) {
|
||||
verifyYRotatedMatrix(angle, 0d, angle, 0d);
|
||||
verifyYRotatedMatrix(-angle, 0d, -angle, 0d);
|
||||
@@ -120,7 +117,7 @@ public class MatrixMathHelperTest {
|
||||
|
||||
@Test
|
||||
public void testDecomposing4x4MatrixToProduceAccurateXaxisAngles() {
|
||||
double[] angles = new double[]{30, 45, 60, 75, 90, 100, 110, 120, 133, 167};
|
||||
double[] angles = new double[] {30, 45, 60, 75, 90, 100, 110, 120, 133, 167};
|
||||
for (double angle : angles) {
|
||||
verifyXRotatedMatrix(angle, angle, 0d, 0d);
|
||||
verifyXRotatedMatrix(-angle, -angle, 0d, 0d);
|
||||
|
||||
+17
-34
@@ -1,35 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.annotations.ReactPropGroup;
|
||||
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import java.util.Date;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Test that verifies that spec of methods annotated with @ReactProp is correct
|
||||
*/
|
||||
/** Test that verifies that spec of methods annotated with @ReactProp is correct */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactPropAnnotationSetterSpecTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private abstract class BaseViewManager extends ViewManager<View, ReactShadowNode> {
|
||||
|
||||
@@ -54,16 +47,14 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateExtraData(View root, Object extraData) {
|
||||
}
|
||||
public void updateExtraData(View root, Object extraData) {}
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testMethodWithWongNumberOfParams() {
|
||||
new BaseViewManager() {
|
||||
@ReactProp(name = "prop")
|
||||
public void setterWithIncorrectNumberOfArgs(View v, boolean value, boolean otherValue) {
|
||||
}
|
||||
public void setterWithIncorrectNumberOfArgs(View v, boolean value, boolean otherValue) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -71,8 +62,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testMethodWithTooFewParams() {
|
||||
new BaseViewManager() {
|
||||
@ReactProp(name = "prop")
|
||||
public void setterWithTooFewParams(View v) {
|
||||
}
|
||||
public void setterWithTooFewParams(View v) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -80,8 +70,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testUnsupportedPropValueType() {
|
||||
new BaseViewManager() {
|
||||
@ReactProp(name = "prop")
|
||||
public void setterWithUnsupportedValueType(View v, Date value) {
|
||||
}
|
||||
public void setterWithUnsupportedValueType(View v, Date value) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -89,8 +78,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testSetterWIthNonViewParam() {
|
||||
new BaseViewManager() {
|
||||
@ReactProp(name = "prop")
|
||||
public void setterWithNonViewParam(Object v, boolean value) {
|
||||
}
|
||||
public void setterWithNonViewParam(Object v, boolean value) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -98,8 +86,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testGroupInvalidNumberOfParams() {
|
||||
new BaseViewManager() {
|
||||
@ReactPropGroup(names = {"prop1", "prop2"})
|
||||
public void setterWIthInvalidNumberOfParams(View v, int index, float value, float other) {
|
||||
}
|
||||
public void setterWIthInvalidNumberOfParams(View v, int index, float value, float other) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -107,8 +94,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testGroupTooFewParams() {
|
||||
new BaseViewManager() {
|
||||
@ReactPropGroup(names = {"prop1", "prop2"})
|
||||
public void setterWIthTooFewParams(View v, int index) {
|
||||
}
|
||||
public void setterWIthTooFewParams(View v, int index) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -116,8 +102,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testGroupNoIndexParam() {
|
||||
new BaseViewManager() {
|
||||
@ReactPropGroup(names = {"prop1", "prop2"})
|
||||
public void setterWithoutIndexParam(View v, float value, float sth) {
|
||||
}
|
||||
public void setterWithoutIndexParam(View v, float value, float sth) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -125,8 +110,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testGroupNoViewParam() {
|
||||
new BaseViewManager() {
|
||||
@ReactPropGroup(names = {"prop1", "prop2"})
|
||||
public void setterWithoutViewParam(Object v, int index, float value) {
|
||||
}
|
||||
public void setterWithoutViewParam(Object v, int index, float value) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
|
||||
@@ -134,8 +118,7 @@ public class ReactPropAnnotationSetterSpecTest {
|
||||
public void testGroupUnsupportedPropType() {
|
||||
new BaseViewManager() {
|
||||
@ReactPropGroup(names = {"prop1", "prop2"})
|
||||
public void setterWithUnsupportedPropType(View v, int index, long value) {
|
||||
}
|
||||
public void setterWithUnsupportedPropType(View v, int index, long value) {}
|
||||
}.getNativeProps();
|
||||
}
|
||||
}
|
||||
|
||||
+50
-43
@@ -1,36 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.annotations.ReactPropGroup;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import android.view.View;
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.annotations.ReactPropGroup;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Test updating view through {@link ViewManager} with {@link ReactProp} and {@link ReactPropGroup}
|
||||
* annotations.
|
||||
@@ -39,21 +36,31 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactPropAnnotationSetterTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
public interface ViewManagerUpdatesReceiver {
|
||||
void onBooleanSetterCalled(boolean value);
|
||||
|
||||
void onIntSetterCalled(int value);
|
||||
|
||||
void onDoubleSetterCalled(double value);
|
||||
|
||||
void onFloatSetterCalled(float value);
|
||||
|
||||
void onStringSetterCalled(String value);
|
||||
|
||||
void onBoxedBooleanSetterCalled(Boolean value);
|
||||
|
||||
void onBoxedIntSetterCalled(Integer value);
|
||||
|
||||
void onArraySetterCalled(ReadableArray value);
|
||||
|
||||
void onMapSetterCalled(ReadableMap value);
|
||||
|
||||
void onFloatGroupPropSetterCalled(int index, float value);
|
||||
|
||||
void onIntGroupPropSetterCalled(int index, int value);
|
||||
|
||||
void onBoxedIntGroupPropSetterCalled(int index, Integer value);
|
||||
}
|
||||
|
||||
@@ -157,42 +164,42 @@ public class ReactPropAnnotationSetterTest {
|
||||
mViewManagerUpdatesReceiver.onMapSetterCalled(value);
|
||||
}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"floatGroupPropFirst",
|
||||
"floatGroupPropSecond",
|
||||
})
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
"floatGroupPropFirst",
|
||||
"floatGroupPropSecond",
|
||||
})
|
||||
public void setFloatGroupProp(View v, int index, float value) {
|
||||
mViewManagerUpdatesReceiver.onFloatGroupPropSetterCalled(index, value);
|
||||
}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"floatGroupPropWithDefaultFirst",
|
||||
"floatGroupPropWithDefaultSecond",
|
||||
}, defaultFloat = -100.0f)
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
"floatGroupPropWithDefaultFirst",
|
||||
"floatGroupPropWithDefaultSecond",
|
||||
},
|
||||
defaultFloat = -100.0f)
|
||||
public void setFloatGroupPropWithDefault(View v, int index, float value) {
|
||||
mViewManagerUpdatesReceiver.onFloatGroupPropSetterCalled(index, value);
|
||||
}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"intGroupPropFirst",
|
||||
"intGroupPropSecond"
|
||||
})
|
||||
@ReactPropGroup(names = {"intGroupPropFirst", "intGroupPropSecond"})
|
||||
public void setIntGroupProp(View v, int index, int value) {
|
||||
mViewManagerUpdatesReceiver.onIntGroupPropSetterCalled(index, value);
|
||||
}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"intGroupPropWithDefaultFirst",
|
||||
"intGroupPropWithDefaultSecond"
|
||||
}, defaultInt = 555)
|
||||
@ReactPropGroup(
|
||||
names = {"intGroupPropWithDefaultFirst", "intGroupPropWithDefaultSecond"},
|
||||
defaultInt = 555)
|
||||
public void setIntGroupPropWithDefault(View v, int index, int value) {
|
||||
mViewManagerUpdatesReceiver.onIntGroupPropSetterCalled(index, value);
|
||||
}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"boxedIntGroupPropFirst",
|
||||
"boxedIntGroupPropSecond",
|
||||
})
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
"boxedIntGroupPropFirst",
|
||||
"boxedIntGroupPropSecond",
|
||||
})
|
||||
public void setBoxedIntGroupProp(View v, int index, Integer value) {
|
||||
mViewManagerUpdatesReceiver.onBoxedIntGroupPropSetterCalled(index, value);
|
||||
}
|
||||
|
||||
+57
-76
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
@@ -28,15 +27,12 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Verifies that prop constants are generated properly based on {@code ReactProp} annotation.
|
||||
*/
|
||||
/** Verifies that prop constants are generated properly based on {@code ReactProp} annotation. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactPropConstantsTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private class ViewManagerUnderTest extends ViewManager<View, ReactShadowNode> {
|
||||
|
||||
@@ -68,103 +64,88 @@ public class ReactPropConstantsTest {
|
||||
}
|
||||
|
||||
@ReactProp(name = "boolProp")
|
||||
public void setBoolProp(View v, boolean value) {
|
||||
}
|
||||
public void setBoolProp(View v, boolean value) {}
|
||||
|
||||
@ReactProp(name = "intProp")
|
||||
public void setIntProp(View v, int value) {
|
||||
}
|
||||
public void setIntProp(View v, int value) {}
|
||||
|
||||
@ReactProp(name = "floatProp")
|
||||
public void setFloatProp(View v, float value) {
|
||||
}
|
||||
public void setFloatProp(View v, float value) {}
|
||||
|
||||
@ReactProp(name = "doubleProp")
|
||||
public void setDoubleProp(View v, double value) {
|
||||
}
|
||||
public void setDoubleProp(View v, double value) {}
|
||||
|
||||
@ReactProp(name = "stringProp")
|
||||
public void setStringProp(View v, String value) {
|
||||
}
|
||||
public void setStringProp(View v, String value) {}
|
||||
|
||||
@ReactProp(name = "boxedBoolProp")
|
||||
public void setBoxedBoolProp(View v, Boolean value) {
|
||||
}
|
||||
public void setBoxedBoolProp(View v, Boolean value) {}
|
||||
|
||||
@ReactProp(name = "boxedIntProp")
|
||||
public void setBoxedIntProp(View v, Integer value) {
|
||||
}
|
||||
public void setBoxedIntProp(View v, Integer value) {}
|
||||
|
||||
@ReactProp(name = "arrayProp")
|
||||
public void setArrayProp(View v, ReadableArray value) {
|
||||
}
|
||||
public void setArrayProp(View v, ReadableArray value) {}
|
||||
|
||||
@ReactProp(name = "mapProp")
|
||||
public void setMapProp(View v, ReadableMap value) {
|
||||
}
|
||||
public void setMapProp(View v, ReadableMap value) {}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"floatGroupPropFirst",
|
||||
"floatGroupPropSecond",
|
||||
})
|
||||
public void setFloatGroupProp(View v, int index, float value) {
|
||||
}
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
"floatGroupPropFirst",
|
||||
"floatGroupPropSecond",
|
||||
})
|
||||
public void setFloatGroupProp(View v, int index, float value) {}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"intGroupPropFirst",
|
||||
"intGroupPropSecond"
|
||||
})
|
||||
public void setIntGroupProp(View v, int index, int value) {
|
||||
}
|
||||
@ReactPropGroup(names = {"intGroupPropFirst", "intGroupPropSecond"})
|
||||
public void setIntGroupProp(View v, int index, int value) {}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"boxedIntGroupPropFirst",
|
||||
"boxedIntGroupPropSecond",
|
||||
})
|
||||
public void setBoxedIntGroupProp(View v, int index, Integer value) {
|
||||
}
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
"boxedIntGroupPropFirst",
|
||||
"boxedIntGroupPropSecond",
|
||||
})
|
||||
public void setBoxedIntGroupProp(View v, int index, Integer value) {}
|
||||
|
||||
@ReactProp(name = "customIntProp", customType = "date")
|
||||
public void customIntProp(View v, int value) {
|
||||
}
|
||||
public void customIntProp(View v, int value) {}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"customBoxedIntGroupPropFirst",
|
||||
"customBoxedIntGroupPropSecond"
|
||||
}, customType = "color")
|
||||
public void customIntGroupProp(View v, int index, Integer value) {
|
||||
}
|
||||
@ReactPropGroup(
|
||||
names = {"customBoxedIntGroupPropFirst", "customBoxedIntGroupPropSecond"},
|
||||
customType = "color")
|
||||
public void customIntGroupProp(View v, int index, Integer value) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativePropsIncludeCorrectTypes() {
|
||||
List<ViewManager> viewManagers = Arrays.<ViewManager>asList(new ViewManagerUnderTest());
|
||||
ReactApplicationContext reactContext = new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(reactContext, viewManagers, 0);
|
||||
ReactApplicationContext reactContext =
|
||||
new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(reactContext, viewManagers, 0);
|
||||
Map<String, String> constants =
|
||||
(Map) valueAtPath(uiManagerModule.getConstants(), "SomeView", "NativeProps");
|
||||
assertThat(constants).isEqualTo(
|
||||
MapBuilder.<String, String>builder()
|
||||
.put("boolProp", "boolean")
|
||||
.put("intProp", "number")
|
||||
.put("doubleProp", "number")
|
||||
.put("floatProp", "number")
|
||||
.put("stringProp", "String")
|
||||
.put("boxedBoolProp", "boolean")
|
||||
.put("boxedIntProp", "number")
|
||||
.put("arrayProp", "Array")
|
||||
.put("mapProp", "Map")
|
||||
.put("floatGroupPropFirst", "number")
|
||||
.put("floatGroupPropSecond", "number")
|
||||
.put("intGroupPropFirst", "number")
|
||||
.put("intGroupPropSecond", "number")
|
||||
.put("boxedIntGroupPropFirst", "number")
|
||||
.put("boxedIntGroupPropSecond", "number")
|
||||
.put("customIntProp", "date")
|
||||
.put("customBoxedIntGroupPropFirst", "color")
|
||||
.put("customBoxedIntGroupPropSecond", "color")
|
||||
.build());
|
||||
assertThat(constants)
|
||||
.isEqualTo(
|
||||
MapBuilder.<String, String>builder()
|
||||
.put("boolProp", "boolean")
|
||||
.put("intProp", "number")
|
||||
.put("doubleProp", "number")
|
||||
.put("floatProp", "number")
|
||||
.put("stringProp", "String")
|
||||
.put("boxedBoolProp", "boolean")
|
||||
.put("boxedIntProp", "number")
|
||||
.put("arrayProp", "Array")
|
||||
.put("mapProp", "Map")
|
||||
.put("floatGroupPropFirst", "number")
|
||||
.put("floatGroupPropSecond", "number")
|
||||
.put("intGroupPropFirst", "number")
|
||||
.put("intGroupPropSecond", "number")
|
||||
.put("boxedIntGroupPropFirst", "number")
|
||||
.put("boxedIntGroupPropSecond", "number")
|
||||
.put("customIntProp", "date")
|
||||
.put("customBoxedIntGroupPropFirst", "color")
|
||||
.put("customBoxedIntGroupPropSecond", "color")
|
||||
.build());
|
||||
}
|
||||
|
||||
private static Object valueAtPath(Map nestedMap, String... keyPath) {
|
||||
|
||||
+19
-9
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -35,21 +34,31 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactPropForShadowNodeSetterTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
public interface ViewManagerUpdatesReceiver {
|
||||
void onBooleanSetterCalled(boolean value);
|
||||
|
||||
void onIntSetterCalled(int value);
|
||||
|
||||
void onDoubleSetterCalled(double value);
|
||||
|
||||
void onFloatSetterCalled(float value);
|
||||
|
||||
void onStringSetterCalled(String value);
|
||||
|
||||
void onBoxedBooleanSetterCalled(Boolean value);
|
||||
|
||||
void onBoxedIntSetterCalled(Integer value);
|
||||
|
||||
void onArraySetterCalled(ReadableArray value);
|
||||
|
||||
void onMapSetterCalled(ReadableMap value);
|
||||
|
||||
void onFloatGroupPropSetterCalled(int index, float value);
|
||||
|
||||
void onIntGroupPropSetterCalled(int index, int value);
|
||||
|
||||
void onBoxedIntGroupPropSetterCalled(int index, Integer value);
|
||||
}
|
||||
|
||||
@@ -80,10 +89,11 @@ public class ReactPropForShadowNodeSetterTest {
|
||||
mViewManagerUpdatesReceiver.onBoxedIntSetterCalled(value);
|
||||
}
|
||||
|
||||
@ReactPropGroup(names = {
|
||||
"floatGroupPropFirst",
|
||||
"floatGroupPropSecond",
|
||||
})
|
||||
@ReactPropGroup(
|
||||
names = {
|
||||
"floatGroupPropFirst",
|
||||
"floatGroupPropSecond",
|
||||
})
|
||||
public void setFloatGroupProp(int index, float value) {
|
||||
mViewManagerUpdatesReceiver.onFloatGroupPropSetterCalled(index, value);
|
||||
}
|
||||
|
||||
+4
-7
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import android.view.View;
|
||||
@@ -26,8 +25,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactPropForShadowNodeSpecTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private static class BaseViewManager extends ViewManager {
|
||||
|
||||
@@ -58,8 +56,7 @@ public class ReactPropForShadowNodeSpecTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateExtraData(View root, Object extraData) {
|
||||
}
|
||||
public void updateExtraData(View root, Object extraData) {}
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
|
||||
+27
-36
@@ -1,56 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.touch.JSResponderHandler;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.fest.assertions.api.Assertions.offset;
|
||||
|
||||
/**
|
||||
* Verify {@link View} view property being applied properly by {@link SimpleViewManager}
|
||||
*/
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.View;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.touch.JSResponderHandler;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/** Verify {@link View} view property being applied properly by {@link SimpleViewManager} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class SimpleViewPropertyTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private static class ConcreteViewManager extends SimpleViewManager<View> {
|
||||
|
||||
@ReactProp(name = "foo")
|
||||
public void setFoo(View view, boolean foo) {
|
||||
}
|
||||
public void setFoo(View view, boolean foo) {}
|
||||
|
||||
@ReactProp(name = "bar")
|
||||
public void setBar(View view, ReadableMap bar) {
|
||||
}
|
||||
public void setBar(View view, ReadableMap bar) {}
|
||||
|
||||
@Override
|
||||
protected View createViewInstance(ThemedReactContext reactContext) {
|
||||
@@ -103,10 +94,10 @@ public class SimpleViewPropertyTest {
|
||||
assertThat(view.getBackground()).isEqualTo(null);
|
||||
|
||||
mManager.updateProperties(view, buildStyles("backgroundColor", 12));
|
||||
assertThat(((ColorDrawable)view.getBackground()).getColor()).isEqualTo(12);
|
||||
assertThat(((ColorDrawable) view.getBackground()).getColor()).isEqualTo(12);
|
||||
|
||||
mManager.updateProperties(view, buildStyles("backgroundColor", null));
|
||||
assertThat(((ColorDrawable)view.getBackground()).getColor()).isEqualTo(0);
|
||||
assertThat(((ColorDrawable) view.getBackground()).getColor()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+35
-43
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
@@ -30,19 +29,15 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class UIManagerModuleConstantsTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private static final String CUSTOM_BUBBLING_EVENT_TYPES = "customBubblingEventTypes";
|
||||
private static final String CUSTOM_DIRECT_EVENT_TYPES = "customDirectEventTypes";
|
||||
|
||||
private static final Map TWIRL_BUBBLING_EVENT_MAP = MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
private static final Map TWIRL_BUBBLING_EVENT_MAP =
|
||||
MapBuilder.of(
|
||||
"bubbled",
|
||||
"onTwirl",
|
||||
"captured",
|
||||
"onTwirlCaptured"));
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of("bubbled", "onTwirl", "captured", "onTwirlCaptured"));
|
||||
private static final Map TWIRL_DIRECT_EVENT_MAP = MapBuilder.of("registrationName", "onTwirl");
|
||||
|
||||
private ReactApplicationContext mReactContext;
|
||||
@@ -55,8 +50,7 @@ public class UIManagerModuleConstantsTest {
|
||||
@Test
|
||||
public void testNoCustomConstants() {
|
||||
List<ViewManager> viewManagers = Arrays.asList(mock(ViewManager.class));
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat(constants)
|
||||
.containsKey(CUSTOM_BUBBLING_EVENT_TYPES)
|
||||
@@ -70,8 +64,7 @@ public class UIManagerModuleConstantsTest {
|
||||
List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
|
||||
when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
|
||||
.thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
|
||||
.contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
|
||||
@@ -84,8 +77,7 @@ public class UIManagerModuleConstantsTest {
|
||||
List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
|
||||
when(mockViewManager.getExportedCustomDirectEventTypeConstants())
|
||||
.thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
|
||||
.contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
|
||||
@@ -99,8 +91,7 @@ public class UIManagerModuleConstantsTest {
|
||||
when(mockViewManager.getName()).thenReturn("RedPandaPhotoOfTheDayView");
|
||||
when(mockViewManager.getExportedViewConstants())
|
||||
.thenReturn(MapBuilder.of("PhotoSizeType", MapBuilder.of("Small", 1, "Large", 2)));
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat(constants).containsKey("RedPandaPhotoOfTheDayView");
|
||||
assertThat((Map) constants.get("RedPandaPhotoOfTheDayView")).containsKey("Constants");
|
||||
@@ -113,10 +104,8 @@ public class UIManagerModuleConstantsTest {
|
||||
ViewManager mockViewManager = mock(ViewManager.class);
|
||||
List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
|
||||
when(mockViewManager.getName()).thenReturn("SomeView");
|
||||
when(mockViewManager.getNativeProps())
|
||||
.thenReturn(MapBuilder.of("fooProp", "number"));
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
when(mockViewManager.getNativeProps()).thenReturn(MapBuilder.of("fooProp", "number"));
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((String) valueAtPath(constants, "SomeView", "NativeProps", "fooProp"))
|
||||
.isEqualTo("number");
|
||||
@@ -125,30 +114,33 @@ public class UIManagerModuleConstantsTest {
|
||||
@Test
|
||||
public void testMergeConstants() {
|
||||
ViewManager managerX = mock(ViewManager.class);
|
||||
when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
|
||||
"onTwirl",
|
||||
MapBuilder.of(
|
||||
"registrationName",
|
||||
"onTwirl",
|
||||
"keyToOverride",
|
||||
"valueX",
|
||||
"mapToMerge",
|
||||
MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));
|
||||
when(managerX.getExportedCustomDirectEventTypeConstants())
|
||||
.thenReturn(
|
||||
MapBuilder.of(
|
||||
"onTwirl",
|
||||
MapBuilder.of(
|
||||
"registrationName",
|
||||
"onTwirl",
|
||||
"keyToOverride",
|
||||
"valueX",
|
||||
"mapToMerge",
|
||||
MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));
|
||||
|
||||
ViewManager managerY = mock(ViewManager.class);
|
||||
when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
|
||||
"onTwirl",
|
||||
MapBuilder.of(
|
||||
"extraKey",
|
||||
"extraValue",
|
||||
"keyToOverride",
|
||||
"valueY",
|
||||
"mapToMerge",
|
||||
MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));
|
||||
when(managerY.getExportedCustomDirectEventTypeConstants())
|
||||
.thenReturn(
|
||||
MapBuilder.of(
|
||||
"onTwirl",
|
||||
MapBuilder.of(
|
||||
"extraKey",
|
||||
"extraValue",
|
||||
"keyToOverride",
|
||||
"valueY",
|
||||
"mapToMerge",
|
||||
MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));
|
||||
|
||||
List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
@@ -53,16 +52,13 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Tests for {@link UIManagerModule}.
|
||||
*/
|
||||
/** Tests for {@link UIManagerModule}. */
|
||||
@PrepareForTest({Arguments.class, ReactChoreographer.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class UIManagerModuleTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ReactApplicationContext mReactContext;
|
||||
private CatalystInstance mCatalystInstanceMock;
|
||||
@@ -73,31 +69,38 @@ public class UIManagerModuleTest {
|
||||
PowerMockito.mockStatic(Arguments.class, ReactChoreographer.class);
|
||||
|
||||
ReactChoreographer choreographerMock = mock(ReactChoreographer.class);
|
||||
PowerMockito.when(Arguments.createArray()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createArray())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyArray();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(ReactChoreographer.getInstance()).thenReturn(choreographerMock);
|
||||
|
||||
mPendingFrameCallbacks = new ArrayList<>();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
mPendingFrameCallbacks
|
||||
.add((ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
}).when(choreographerMock).postFrameCallback(
|
||||
any(ReactChoreographer.CallbackType.class),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
doAnswer(
|
||||
new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
mPendingFrameCallbacks.add(
|
||||
(ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.when(choreographerMock)
|
||||
.postFrameCallback(
|
||||
any(ReactChoreographer.CallbackType.class),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
|
||||
mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
|
||||
mReactContext = new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
@@ -151,31 +154,15 @@ public class UIManagerModuleTest {
|
||||
int subViewTag = viewTag + 1;
|
||||
|
||||
uiManager.createView(
|
||||
viewTag,
|
||||
ReactViewManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of("collapsable", false));
|
||||
viewTag, ReactViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false));
|
||||
uiManager.createView(
|
||||
subViewTag,
|
||||
ReactViewManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of("collapsable", false));
|
||||
subViewTag, ReactViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false));
|
||||
|
||||
uiManager.manageChildren(
|
||||
viewTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(subViewTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
viewTag, null, null, JavaOnlyArray.of(subViewTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.manageChildren(
|
||||
rootTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(viewTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
rootTag, null, null, JavaOnlyArray.of(viewTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -201,12 +188,7 @@ public class UIManagerModuleTest {
|
||||
View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(3);
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
JavaOnlyArray.of(1, 0, 2),
|
||||
JavaOnlyArray.of(0, 2, 1),
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
hierarchy.rootView, JavaOnlyArray.of(1, 0, 2), JavaOnlyArray.of(0, 2, 1), null, null, null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -227,21 +209,12 @@ public class UIManagerModuleTest {
|
||||
View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(1);
|
||||
View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2);
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(0, 3));
|
||||
uiManager.manageChildren(hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(0, 3));
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
|
||||
assertChildrenAreExactly(
|
||||
hierarchy.nativeRootView,
|
||||
expectedViewAt0,
|
||||
expectedViewAt1);
|
||||
assertChildrenAreExactly(hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -265,10 +238,7 @@ public class UIManagerModuleTest {
|
||||
executePendingFrameCallbacks();
|
||||
|
||||
assertChildrenAreExactly(
|
||||
hierarchy.nativeRootView,
|
||||
expectedViewAt0,
|
||||
expectedViewAt1,
|
||||
expectedViewAt2);
|
||||
hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1, expectedViewAt2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalViewOperationException.class)
|
||||
@@ -293,13 +263,7 @@ public class UIManagerModuleTest {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(3, 3));
|
||||
uiManager.manageChildren(hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(3, 3));
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -351,12 +315,7 @@ public class UIManagerModuleTest {
|
||||
View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(3);
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
JavaOnlyArray.of(1, 2),
|
||||
JavaOnlyArray.of(2, 1),
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
hierarchy.rootView, JavaOnlyArray.of(1, 2), JavaOnlyArray.of(2, 1), null, null, null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -379,22 +338,13 @@ public class UIManagerModuleTest {
|
||||
View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2);
|
||||
View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(3);
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(1));
|
||||
uiManager.manageChildren(hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(1));
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
|
||||
assertChildrenAreExactly(
|
||||
hierarchy.nativeRootView,
|
||||
expectedViewAt0,
|
||||
expectedViewAt1,
|
||||
expectedViewAt2);
|
||||
hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1, expectedViewAt2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -408,16 +358,11 @@ public class UIManagerModuleTest {
|
||||
newViewTag,
|
||||
ReactViewManager.REACT_CLASS,
|
||||
hierarchy.rootView,
|
||||
JavaOnlyMap
|
||||
.of("left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0, "collapsable", false));
|
||||
JavaOnlyMap.of(
|
||||
"left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0, "collapsable", false));
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(newViewTag),
|
||||
JavaOnlyArray.of(4),
|
||||
null);
|
||||
hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -430,9 +375,7 @@ public class UIManagerModuleTest {
|
||||
assertThat(newView.getHeight()).isEqualTo(40);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is to make sure we execute enqueued operations in the order given by JS.
|
||||
*/
|
||||
/** This is to make sure we execute enqueued operations in the order given by JS. */
|
||||
@Test
|
||||
public void testAddUpdateRemoveInSingleBatch() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
@@ -447,25 +390,12 @@ public class UIManagerModuleTest {
|
||||
JavaOnlyMap.of("collapsable", false));
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(newViewTag),
|
||||
JavaOnlyArray.of(4),
|
||||
null);
|
||||
hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null);
|
||||
|
||||
uiManager.updateView(
|
||||
newViewTag,
|
||||
ReactViewManager.REACT_CLASS,
|
||||
JavaOnlyMap.of("backgroundColor", Color.RED));
|
||||
newViewTag, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("backgroundColor", Color.RED));
|
||||
|
||||
uiManager.manageChildren(
|
||||
hierarchy.rootView,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(4));
|
||||
uiManager.manageChildren(hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(4));
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -536,8 +466,7 @@ public class UIManagerModuleTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
}
|
||||
public void run() {}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -610,10 +539,7 @@ public class UIManagerModuleTest {
|
||||
final int containerSiblingTag = containerTag + 1;
|
||||
|
||||
uiManager.createView(
|
||||
containerTag,
|
||||
ReactViewManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of("collapsable", false));
|
||||
containerTag, ReactViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false));
|
||||
uiManager.createView(
|
||||
containerSiblingTag,
|
||||
ReactViewManager.REACT_CLASS,
|
||||
@@ -662,10 +588,7 @@ public class UIManagerModuleTest {
|
||||
int rawTextTag = textTag + 1;
|
||||
|
||||
uiManager.createView(
|
||||
textTag,
|
||||
ReactTextViewManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of("collapsable", false));
|
||||
textTag, ReactTextViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false));
|
||||
uiManager.createView(
|
||||
rawTextTag,
|
||||
ReactRawTextManager.REACT_CLASS,
|
||||
@@ -673,20 +596,10 @@ public class UIManagerModuleTest {
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, text, "collapsable", false));
|
||||
|
||||
uiManager.manageChildren(
|
||||
textTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(rawTextTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
textTag, null, null, JavaOnlyArray.of(rawTextTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.manageChildren(
|
||||
rootTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(textTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
rootTag, null, null, JavaOnlyArray.of(textTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -747,34 +660,22 @@ public class UIManagerModuleTest {
|
||||
|
||||
private void addChild(UIManagerModule uiManager, int parentTag, int childTag, int index) {
|
||||
uiManager.manageChildren(
|
||||
parentTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(childTag),
|
||||
JavaOnlyArray.of(index),
|
||||
null);
|
||||
parentTag, null, null, JavaOnlyArray.of(childTag), JavaOnlyArray.of(index), null);
|
||||
}
|
||||
|
||||
private void assertChildrenAreExactly(ViewGroup parent, View... views) {
|
||||
assertThat(parent.getChildCount()).isEqualTo(views.length);
|
||||
for (int i = 0; i < views.length; i++) {
|
||||
assertThat(parent.getChildAt(i))
|
||||
.describedAs("View at " + i)
|
||||
.isEqualTo(views[i]);
|
||||
assertThat(parent.getChildAt(i)).describedAs("View at " + i).isEqualTo(views[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holder for the tags that represent that represent views in the following hierarchy:
|
||||
* - View rootView
|
||||
* - View view0
|
||||
* - View viewWithChildren1
|
||||
* - View childView0
|
||||
* - View childView1
|
||||
* - View view2
|
||||
* - View view3
|
||||
* Holder for the tags that represent that represent views in the following hierarchy: - View
|
||||
* rootView - View view0 - View viewWithChildren1 - View childView0 - View childView1 - View view2
|
||||
* - View view3
|
||||
*
|
||||
* This hierarchy is used to test move/delete functionality in manageChildren.
|
||||
* <p>This hierarchy is used to test move/delete functionality in manageChildren.
|
||||
*/
|
||||
private static class TestMoveDeleteHierarchy {
|
||||
|
||||
@@ -809,12 +710,10 @@ public class UIManagerModuleTest {
|
||||
}
|
||||
|
||||
private UIManagerModule getUIManagerModule() {
|
||||
List<ViewManager> viewManagers = Arrays.<ViewManager>asList(
|
||||
new ReactViewManager(),
|
||||
new ReactTextViewManager(),
|
||||
new ReactRawTextManager());
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
List<ViewManager> viewManagers =
|
||||
Arrays.<ViewManager>asList(
|
||||
new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager());
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(mReactContext, viewManagers, 0);
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,18 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.uimanager.layoutanimation;
|
||||
|
||||
import com.facebook.react.uimanager.layoutanimation.InterpolatorType;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class InterpolatorTypeTest {
|
||||
@@ -22,7 +21,8 @@ public class InterpolatorTypeTest {
|
||||
assertThat(InterpolatorType.fromString("linear")).isEqualTo(InterpolatorType.LINEAR);
|
||||
assertThat(InterpolatorType.fromString("easeIn")).isEqualTo(InterpolatorType.EASE_IN);
|
||||
assertThat(InterpolatorType.fromString("easeOut")).isEqualTo(InterpolatorType.EASE_OUT);
|
||||
assertThat(InterpolatorType.fromString("easeInEaseOut")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
|
||||
assertThat(InterpolatorType.fromString("easeInEaseOut"))
|
||||
.isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
|
||||
assertThat(InterpolatorType.fromString("spring")).isEqualTo(InterpolatorType.SPRING);
|
||||
}
|
||||
|
||||
@@ -30,13 +30,15 @@ public class InterpolatorTypeTest {
|
||||
public void testOtherCases() {
|
||||
assertThat(InterpolatorType.fromString("EASEIN")).isEqualTo(InterpolatorType.EASE_IN);
|
||||
assertThat(InterpolatorType.fromString("easeout")).isEqualTo(InterpolatorType.EASE_OUT);
|
||||
assertThat(InterpolatorType.fromString("easeineaseout")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
|
||||
assertThat(InterpolatorType.fromString("easeineaseout"))
|
||||
.isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocales() {
|
||||
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
|
||||
assertThat(InterpolatorType.fromString("easeInEaseOut")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
|
||||
assertThat(InterpolatorType.fromString("easeInEaseOut"))
|
||||
.isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
@@ -1,40 +1,95 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JSStackTraceTest {
|
||||
|
||||
@Test
|
||||
public void testSymbolication() {
|
||||
JavaOnlyArray values = JavaOnlyArray.of(
|
||||
JavaOnlyMap.of("methodName", "method_from_bundle", "column", 11, "lineNumber", 7, "file", "Fb4aBundle.js"),
|
||||
JavaOnlyMap.of("methodName", "method_from_ram_bundle", "column", 13, "lineNumber", 18, "file", "199.js"),
|
||||
JavaOnlyMap.of("methodName", "method_from_ram_bundle_with_address", "column", 13, "lineNumber", 18, "file", "address at 199.js"),
|
||||
JavaOnlyMap.of("methodName", "method_from_segment", "column", 18, "lineNumber", 9, "file", "seg-1.js"),
|
||||
JavaOnlyMap.of("methodName", "method_from_segment_with_address", "column", 18, "lineNumber", 9, "file", "address at seg-1.js"),
|
||||
JavaOnlyMap.of("methodName", "method_from_ram_segment", "column", 20, "lineNumber", 10, "file", "seg-3_198.js"),
|
||||
JavaOnlyMap.of("methodName", "method_from_ram_segment_with_address", "column", 20, "lineNumber", 10, "file", "address at seg-3_198.js")
|
||||
);
|
||||
JavaOnlyArray values =
|
||||
JavaOnlyArray.of(
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_bundle",
|
||||
"column",
|
||||
11,
|
||||
"lineNumber",
|
||||
7,
|
||||
"file",
|
||||
"Fb4aBundle.js"),
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_ram_bundle",
|
||||
"column",
|
||||
13,
|
||||
"lineNumber",
|
||||
18,
|
||||
"file",
|
||||
"199.js"),
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_ram_bundle_with_address",
|
||||
"column",
|
||||
13,
|
||||
"lineNumber",
|
||||
18,
|
||||
"file",
|
||||
"address at 199.js"),
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_segment",
|
||||
"column",
|
||||
18,
|
||||
"lineNumber",
|
||||
9,
|
||||
"file",
|
||||
"seg-1.js"),
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_segment_with_address",
|
||||
"column",
|
||||
18,
|
||||
"lineNumber",
|
||||
9,
|
||||
"file",
|
||||
"address at seg-1.js"),
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_ram_segment",
|
||||
"column",
|
||||
20,
|
||||
"lineNumber",
|
||||
10,
|
||||
"file",
|
||||
"seg-3_198.js"),
|
||||
JavaOnlyMap.of(
|
||||
"methodName",
|
||||
"method_from_ram_segment_with_address",
|
||||
"column",
|
||||
20,
|
||||
"lineNumber",
|
||||
10,
|
||||
"file",
|
||||
"address at seg-3_198.js"));
|
||||
String message = JSStackTrace.format("Error", values);
|
||||
Assert.assertEquals(message, "Error, stack:\n"
|
||||
+ "method_from_bundle@7:11\n"
|
||||
+ "method_from_ram_bundle@199.js:18:13\n"
|
||||
+ "method_from_ram_bundle_with_address@199.js:18:13\n"
|
||||
+ "method_from_segment@seg-1.js:9:18\n"
|
||||
+ "method_from_segment_with_address@seg-1.js:9:18\n"
|
||||
+ "method_from_ram_segment@seg-3_198.js:10:20\n"
|
||||
+ "method_from_ram_segment_with_address@seg-3_198.js:10:20\n"
|
||||
);
|
||||
Assert.assertEquals(
|
||||
message,
|
||||
"Error, stack:\n"
|
||||
+ "method_from_bundle@7:11\n"
|
||||
+ "method_from_ram_bundle@199.js:18:13\n"
|
||||
+ "method_from_ram_bundle_with_address@199.js:18:13\n"
|
||||
+ "method_from_segment@seg-1.js:9:18\n"
|
||||
+ "method_from_segment_with_address@seg-1.js:9:18\n"
|
||||
+ "method_from_ram_segment@seg-3_198.js:10:20\n"
|
||||
+ "method_from_ram_segment_with_address@seg-3_198.js:10:20\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-20
@@ -1,50 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.image;
|
||||
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ImageResizeModeTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Test
|
||||
public void testImageResizeMode() {
|
||||
assertThat(ImageResizeMode.toScaleType(null))
|
||||
.isEqualTo(ScalingUtils.ScaleType.CENTER_CROP);
|
||||
assertThat(ImageResizeMode.toScaleType(null)).isEqualTo(ScalingUtils.ScaleType.CENTER_CROP);
|
||||
|
||||
assertThat(ImageResizeMode.toScaleType("contain"))
|
||||
.isEqualTo(ScalingUtils.ScaleType.FIT_CENTER);
|
||||
assertThat(ImageResizeMode.toScaleType("contain")).isEqualTo(ScalingUtils.ScaleType.FIT_CENTER);
|
||||
|
||||
assertThat(ImageResizeMode.toScaleType("cover"))
|
||||
.isEqualTo(ScalingUtils.ScaleType.CENTER_CROP);
|
||||
assertThat(ImageResizeMode.toScaleType("cover")).isEqualTo(ScalingUtils.ScaleType.CENTER_CROP);
|
||||
|
||||
assertThat(ImageResizeMode.toScaleType("stretch"))
|
||||
.isEqualTo(ScalingUtils.ScaleType.FIT_XY);
|
||||
assertThat(ImageResizeMode.toScaleType("stretch")).isEqualTo(ScalingUtils.ScaleType.FIT_XY);
|
||||
|
||||
assertThat(ImageResizeMode.toScaleType("center"))
|
||||
.isEqualTo(ScalingUtils.ScaleType.CENTER_INSIDE);
|
||||
|
||||
// No resizeMode set
|
||||
assertThat(ImageResizeMode.defaultValue())
|
||||
.isEqualTo(ScalingUtils.ScaleType.CENTER_CROP);
|
||||
assertThat(ImageResizeMode.defaultValue()).isEqualTo(ScalingUtils.ScaleType.CENTER_CROP);
|
||||
}
|
||||
}
|
||||
|
||||
+36
-41
@@ -1,52 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.image;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Robolectric;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.DisplayMetrics;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Verify that {@link ScalingUtils} properties are being applied correctly
|
||||
* by {@link ReactImageManager}.
|
||||
* Verify that {@link ScalingUtils} properties are being applied correctly by {@link
|
||||
* ReactImageManager}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactImagePropertyTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ReactApplicationContext mContext;
|
||||
private CatalystInstance mCatalystInstanceMock;
|
||||
@@ -72,7 +67,7 @@ public class ReactImagePropertyTest {
|
||||
return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
|
||||
}
|
||||
|
||||
@Test(expected=JSApplicationIllegalArgumentException.class)
|
||||
@Test(expected = JSApplicationIllegalArgumentException.class)
|
||||
public void testImageInvalidResizeMode() {
|
||||
ReactImageManager viewManager = new ReactImageManager();
|
||||
ReactImageView view = viewManager.createViewInstance(mThemeContext);
|
||||
@@ -84,8 +79,8 @@ public class ReactImagePropertyTest {
|
||||
ReactImageManager viewManager = new ReactImageManager();
|
||||
ReactImageView view = viewManager.createViewInstance(mThemeContext);
|
||||
viewManager.updateProperties(
|
||||
view,
|
||||
buildStyles("src", JavaOnlyArray.of(JavaOnlyMap.of("uri", "http://mysite.com/mypic.jpg"))));
|
||||
view,
|
||||
buildStyles("src", JavaOnlyArray.of(JavaOnlyMap.of("uri", "http://mysite.com/mypic.jpg"))));
|
||||
|
||||
viewManager.updateProperties(view, buildStyles("borderColor", Color.argb(0, 0, 255, 255)));
|
||||
int borderColor = view.getHierarchy().getRoundingParams().getBorderColor();
|
||||
@@ -114,8 +109,8 @@ public class ReactImagePropertyTest {
|
||||
ReactImageManager viewManager = new ReactImageManager();
|
||||
ReactImageView view = viewManager.createViewInstance(mThemeContext);
|
||||
viewManager.updateProperties(
|
||||
view,
|
||||
buildStyles("src", JavaOnlyArray.of(JavaOnlyMap.of("uri", "http://mysite.com/mypic.jpg"))));
|
||||
view,
|
||||
buildStyles("src", JavaOnlyArray.of(JavaOnlyMap.of("uri", "http://mysite.com/mypic.jpg"))));
|
||||
|
||||
// We can't easily verify if rounded corner was honored or not, this tests simply verifies
|
||||
// we're not crashing..
|
||||
@@ -130,9 +125,9 @@ public class ReactImagePropertyTest {
|
||||
ReactImageView view = viewManager.createViewInstance(mThemeContext);
|
||||
assertNull(view.getColorFilter());
|
||||
viewManager.updateProperties(view, buildStyles("tintColor", Color.argb(50, 0, 0, 255)));
|
||||
// Can't actually assert the specific color so this is the next best thing.
|
||||
// Does the color filter now exist?
|
||||
assertNotNull(view.getColorFilter());
|
||||
// Can't actually assert the specific color so this is the next best thing.
|
||||
// Does the color filter now exist?
|
||||
assertNotNull(view.getColorFilter());
|
||||
viewManager.updateProperties(view, buildStyles("tintColor", null));
|
||||
assertNull(view.getColorFilter());
|
||||
}
|
||||
|
||||
+6
-10
@@ -1,12 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.slider;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import android.widget.SeekBar;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
@@ -23,17 +24,12 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verify {@link SeekBar} view property being applied properly by {@link ReactSliderManager}
|
||||
*/
|
||||
/** Verify {@link SeekBar} view property being applied properly by {@link ReactSliderManager} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactSliderPropertyTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ThemedReactContext mThemedContext;
|
||||
private ReactSliderManager mManager;
|
||||
|
||||
+4
-5
@@ -1,15 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.text;
|
||||
|
||||
import android.graphics.Paint;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.text;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
@@ -33,9 +32,7 @@ import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.views.text.ReactRawTextShadowNode;
|
||||
import com.facebook.react.views.view.ReactViewBackgroundDrawable;
|
||||
import com.facebook.react.views.text.CustomTextTransformSpan;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -52,16 +49,13 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Tests for {@link UIManagerModule} specifically for React Text/RawText.
|
||||
*/
|
||||
/** Tests for {@link UIManagerModule} specifically for React Text/RawText. */
|
||||
@PrepareForTest({Arguments.class, ReactChoreographer.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactTextTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ArrayList<ChoreographerCompat.FrameCallback> mPendingFrameCallbacks;
|
||||
|
||||
@@ -70,38 +64,44 @@ public class ReactTextTest {
|
||||
PowerMockito.mockStatic(Arguments.class, ReactChoreographer.class);
|
||||
|
||||
ReactChoreographer uiDriverMock = mock(ReactChoreographer.class);
|
||||
PowerMockito.when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(ReactChoreographer.getInstance()).thenReturn(uiDriverMock);
|
||||
|
||||
mPendingFrameCallbacks = new ArrayList<>();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
mPendingFrameCallbacks
|
||||
.add((ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
}).when(uiDriverMock).postFrameCallback(
|
||||
any(ReactChoreographer.CallbackType.class),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
doAnswer(
|
||||
new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
mPendingFrameCallbacks.add(
|
||||
(ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.when(uiDriverMock)
|
||||
.postFrameCallback(
|
||||
any(ReactChoreographer.CallbackType.class),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFontSizeApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_SIZE, 21.0),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_SIZE, 21.0),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
AbsoluteSizeSpan sizeSpan = getSingleSpan(
|
||||
(TextView) rootView.getChildAt(0), AbsoluteSizeSpan.class);
|
||||
AbsoluteSizeSpan sizeSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), AbsoluteSizeSpan.class);
|
||||
assertThat(sizeSpan.getSize()).isEqualTo(21);
|
||||
}
|
||||
|
||||
@@ -109,10 +109,11 @@ public class ReactTextTest {
|
||||
public void testBoldFontApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -124,10 +125,11 @@ public class ReactTextTest {
|
||||
public void testNumericBoldFontApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "500"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "500"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -139,10 +141,11 @@ public class ReactTextTest {
|
||||
public void testItalicFontApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -154,10 +157,11 @@ public class ReactTextTest {
|
||||
public void testBoldItalicFontApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold", ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold", ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -169,10 +173,11 @@ public class ReactTextTest {
|
||||
public void testNormalFontWeightApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "normal"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "normal"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -183,10 +188,11 @@ public class ReactTextTest {
|
||||
public void testNumericNormalFontWeightApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "200"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "200"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -197,10 +203,11 @@ public class ReactTextTest {
|
||||
public void testNormalFontStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_STYLE, "normal"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_STYLE, "normal"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -211,10 +218,11 @@ public class ReactTextTest {
|
||||
public void testFontFamilyStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -227,10 +235,11 @@ public class ReactTextTest {
|
||||
public void testFontFamilyBoldStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_WEIGHT, "bold"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_WEIGHT, "bold"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -243,10 +252,11 @@ public class ReactTextTest {
|
||||
public void testFontFamilyItalicStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -259,13 +269,14 @@ public class ReactTextTest {
|
||||
public void testFontFamilyBoldItalicStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(
|
||||
ViewProps.FONT_FAMILY, "sans-serif",
|
||||
ViewProps.FONT_WEIGHT, "500",
|
||||
ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(
|
||||
ViewProps.FONT_FAMILY, "sans-serif",
|
||||
ViewProps.FONT_WEIGHT, "500",
|
||||
ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -278,10 +289,11 @@ public class ReactTextTest {
|
||||
public void testTextDecorationLineUnderlineApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
@@ -296,17 +308,16 @@ public class ReactTextTest {
|
||||
public void testTextDecorationLineLineThroughApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
UnderlineSpan[] underlineSpans =
|
||||
text.getSpans(0, text.length(), UnderlineSpan.class);
|
||||
StrikethroughSpan strikeThroughSpan =
|
||||
getSingleSpan(textView, StrikethroughSpan.class);
|
||||
UnderlineSpan[] underlineSpans = text.getSpans(0, text.length(), UnderlineSpan.class);
|
||||
StrikethroughSpan strikeThroughSpan = getSingleSpan(textView, StrikethroughSpan.class);
|
||||
assertThat(underlineSpans).hasSize(0);
|
||||
assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
|
||||
}
|
||||
@@ -315,10 +326,11 @@ public class ReactTextTest {
|
||||
public void testTextDecorationLineUnderlineLineThroughApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
UnderlineSpan underlineSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
|
||||
@@ -332,10 +344,11 @@ public class ReactTextTest {
|
||||
public void testBackgroundColorStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.BACKGROUND_COLOR, Color.BLUE),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.BACKGROUND_COLOR, Color.BLUE),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
Drawable backgroundDrawable = ((TextView) rootView.getChildAt(0)).getBackground();
|
||||
assertThat(((ReactViewBackgroundDrawable) backgroundDrawable).getColor()).isEqualTo(Color.BLUE);
|
||||
@@ -345,13 +358,15 @@ public class ReactTextTest {
|
||||
public void testTextTransformNoneApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextEntered =
|
||||
".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = testTextEntered;
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "none"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "none"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
@@ -361,13 +376,16 @@ public class ReactTextTest {
|
||||
public void testTextTransformUppercaseApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = ".AA\tBB\t\tCC DD EE \r\nZZ I LIKE TO EAT APPLES. \n中文ÉÉ 我喜欢吃苹果。AWDAWD ";
|
||||
String testTextEntered =
|
||||
".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed =
|
||||
".AA\tBB\t\tCC DD EE \r\nZZ I LIKE TO EAT APPLES. \n中文ÉÉ 我喜欢吃苹果。AWDAWD ";
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "uppercase"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "uppercase"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
@@ -377,13 +395,16 @@ public class ReactTextTest {
|
||||
public void testTextTransformLowercaseApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = ".aa\tbb\t\tcc dd ee \r\nzz i like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextEntered =
|
||||
".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed =
|
||||
".aa\tbb\t\tcc dd ee \r\nzz i like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "lowercase"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "lowercase"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
@@ -393,13 +414,16 @@ public class ReactTextTest {
|
||||
public void testTextTransformCapitalizeApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = ".Aa\tBb\t\tCc Dd Ee \r\nZz I Like To Eat Apples. \n中文Éé 我喜欢吃苹果。Awdawd ";
|
||||
String testTextEntered =
|
||||
".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed =
|
||||
".Aa\tBb\t\tCc Dd Ee \r\nZz I Like To Eat Apples. \n中文Éé 我喜欢吃苹果。Awdawd ";
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "capitalize"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "capitalize"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
@@ -409,10 +433,11 @@ public class ReactTextTest {
|
||||
public void testMaxLinesApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.NUMBER_OF_LINES, 2),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.NUMBER_OF_LINES, 2),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo("test text");
|
||||
@@ -425,7 +450,8 @@ public class ReactTextTest {
|
||||
public void testTextAlignJustifyApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
ReactRootView rootView =
|
||||
createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textAlign", "justify"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
@@ -435,9 +461,7 @@ public class ReactTextTest {
|
||||
assertThat(textView.getJustificationMode()).isEqualTo(Layout.JUSTIFICATION_MODE_INTER_WORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure TextView has exactly one span and that span has given type.
|
||||
*/
|
||||
/** Make sure TextView has exactly one span and that span has given type. */
|
||||
private static <TSPAN> TSPAN getSingleSpan(TextView textView, Class<TSPAN> spanClass) {
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
TSPAN[] spans = text.getSpans(0, text.length(), spanClass);
|
||||
@@ -446,40 +470,20 @@ public class ReactTextTest {
|
||||
}
|
||||
|
||||
private ReactRootView createText(
|
||||
UIManagerModule uiManager,
|
||||
JavaOnlyMap textProps,
|
||||
JavaOnlyMap rawTextProps) {
|
||||
UIManagerModule uiManager, JavaOnlyMap textProps, JavaOnlyMap rawTextProps) {
|
||||
ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
|
||||
int rootTag = uiManager.addRootView(rootView);
|
||||
int textTag = rootTag + 1;
|
||||
int rawTextTag = textTag + 1;
|
||||
|
||||
uiManager.createView(
|
||||
textTag,
|
||||
ReactTextViewManager.REACT_CLASS,
|
||||
rootTag,
|
||||
textProps);
|
||||
uiManager.createView(
|
||||
rawTextTag,
|
||||
ReactRawTextManager.REACT_CLASS,
|
||||
rootTag,
|
||||
rawTextProps);
|
||||
uiManager.createView(textTag, ReactTextViewManager.REACT_CLASS, rootTag, textProps);
|
||||
uiManager.createView(rawTextTag, ReactRawTextManager.REACT_CLASS, rootTag, rawTextProps);
|
||||
|
||||
uiManager.manageChildren(
|
||||
textTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(rawTextTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
textTag, null, null, JavaOnlyArray.of(rawTextTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.manageChildren(
|
||||
rootTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(textTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
rootTag, null, null, JavaOnlyArray.of(textTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -497,13 +501,12 @@ public class ReactTextTest {
|
||||
|
||||
public UIManagerModule getUIManagerModule() {
|
||||
ReactApplicationContext reactContext = ReactTestHelper.createCatalystContextForTest();
|
||||
List<ViewManager> viewManagers = Arrays.asList(
|
||||
new ViewManager[] {
|
||||
new ReactTextViewManager(),
|
||||
new ReactRawTextManager(),
|
||||
});
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(reactContext, viewManagers, 0);
|
||||
List<ViewManager> viewManagers =
|
||||
Arrays.asList(
|
||||
new ViewManager[] {
|
||||
new ReactTextViewManager(), new ReactRawTextManager(),
|
||||
});
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(reactContext, viewManagers, 0);
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
||||
+42
-53
@@ -1,54 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.textinput;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.text.InputType;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.Layout;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.JSApplicationCausedNativeException;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.views.text.DefaultStyleValuesUtil;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
|
||||
import com.facebook.react.views.text.DefaultStyleValuesUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verify {@link EditText} view property being applied properly by {@link ReactTextInputManager}
|
||||
*/
|
||||
/** Verify {@link EditText} view property being applied properly by {@link ReactTextInputManager} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ReactTextInputPropertyTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ReactApplicationContext mContext;
|
||||
private CatalystInstance mCatalystInstanceMock;
|
||||
@@ -100,29 +92,24 @@ public class ReactTextInputPropertyTest {
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS).isZero();
|
||||
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("autoCapitalize", InputType.TYPE_TEXT_FLAG_CAP_SENTENCES));
|
||||
view, buildStyles("autoCapitalize", InputType.TYPE_TEXT_FLAG_CAP_SENTENCES));
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).isNotZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_WORDS).isZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS).isZero();
|
||||
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("autoCapitalize", InputType.TYPE_TEXT_FLAG_CAP_WORDS));
|
||||
view, buildStyles("autoCapitalize", InputType.TYPE_TEXT_FLAG_CAP_WORDS));
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).isZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_WORDS).isNotZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS).isZero();
|
||||
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("autoCapitalize", InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS));
|
||||
view, buildStyles("autoCapitalize", InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS));
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).isZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_WORDS).isZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS).isNotZero();
|
||||
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("autoCapitalize", InputType.TYPE_CLASS_TEXT));
|
||||
mManager.updateProperties(view, buildStyles("autoCapitalize", InputType.TYPE_CLASS_TEXT));
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).isZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_WORDS).isZero();
|
||||
assertThat(view.getInputType() & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS).isZero();
|
||||
@@ -166,8 +153,7 @@ public class ReactTextInputPropertyTest {
|
||||
ReactEditText view = mManager.createViewInstance(mThemedContext);
|
||||
|
||||
final ColorStateList defaultPlaceholderColorStateList =
|
||||
DefaultStyleValuesUtil.getDefaultTextColorHint(
|
||||
view.getContext());
|
||||
DefaultStyleValuesUtil.getDefaultTextColorHint(view.getContext());
|
||||
|
||||
ColorStateList colors = view.getHintTextColors();
|
||||
assertThat(colors).isEqualTo(defaultPlaceholderColorStateList);
|
||||
@@ -236,16 +222,19 @@ public class ReactTextInputPropertyTest {
|
||||
int numberPadTypeFlags = InputType.TYPE_CLASS_NUMBER;
|
||||
int decimalPadTypeFlags = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||
int numericTypeFlags =
|
||||
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
| InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
| InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
int emailTypeFlags = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_CLASS_TEXT;
|
||||
int passwordVisibilityFlag = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &
|
||||
~InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
int passwordVisibilityFlag =
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD & ~InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
|
||||
int generalKeyboardTypeFlags = numericTypeFlags |
|
||||
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS |
|
||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_PHONE |
|
||||
passwordVisibilityFlag;
|
||||
int generalKeyboardTypeFlags =
|
||||
numericTypeFlags
|
||||
| InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
||||
| InputType.TYPE_CLASS_TEXT
|
||||
| InputType.TYPE_CLASS_PHONE
|
||||
| passwordVisibilityFlag;
|
||||
|
||||
mManager.updateProperties(view, buildStyles());
|
||||
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);
|
||||
@@ -266,7 +255,8 @@ public class ReactTextInputPropertyTest {
|
||||
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(emailTypeFlags);
|
||||
|
||||
mManager.updateProperties(view, buildStyles("keyboardType", "phone-pad"));
|
||||
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_PHONE);
|
||||
assertThat(view.getInputType() & generalKeyboardTypeFlags)
|
||||
.isEqualTo(InputType.TYPE_CLASS_PHONE);
|
||||
|
||||
mManager.updateProperties(view, buildStyles("keyboardType", "visible-password"));
|
||||
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(passwordVisibilityFlag);
|
||||
@@ -343,9 +333,11 @@ public class ReactTextInputPropertyTest {
|
||||
mManager.updateProperties(view, buildStyles("textAlign", "right"));
|
||||
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(Gravity.RIGHT);
|
||||
mManager.updateProperties(view, buildStyles("textAlign", "center"));
|
||||
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(Gravity.CENTER_HORIZONTAL);
|
||||
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK)
|
||||
.isEqualTo(Gravity.CENTER_HORIZONTAL);
|
||||
mManager.updateProperties(view, buildStyles("textAlign", null));
|
||||
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(defaultHorizontalGravity);
|
||||
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK)
|
||||
.isEqualTo(defaultHorizontalGravity);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mManager.updateProperties(view, buildStyles("textAlign", "justify"));
|
||||
assertThat(view.getJustificationMode()).isEqualTo(Layout.JUSTIFICATION_MODE_INTER_WORD);
|
||||
@@ -357,29 +349,26 @@ public class ReactTextInputPropertyTest {
|
||||
mManager.updateProperties(view, buildStyles("textAlignVertical", "bottom"));
|
||||
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(Gravity.BOTTOM);
|
||||
mManager.updateProperties(view, buildStyles("textAlignVertical", "center"));
|
||||
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(Gravity.CENTER_VERTICAL);
|
||||
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK)
|
||||
.isEqualTo(Gravity.CENTER_VERTICAL);
|
||||
mManager.updateProperties(view, buildStyles("textAlignVertical", null));
|
||||
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(defaultVerticalGravity);
|
||||
|
||||
// TextAlign + TextAlignVertical
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("textAlign", "center", "textAlignVertical", "center"));
|
||||
view, buildStyles("textAlign", "center", "textAlignVertical", "center"));
|
||||
assertThat(view.getGravity()).isEqualTo(Gravity.CENTER);
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("textAlign", "right", "textAlignVertical", "bottom"));
|
||||
view, buildStyles("textAlign", "right", "textAlignVertical", "bottom"));
|
||||
assertThat(view.getGravity()).isEqualTo(Gravity.RIGHT | Gravity.BOTTOM);
|
||||
mManager.updateProperties(
|
||||
view,
|
||||
buildStyles("textAlign", null, "textAlignVertical", null));
|
||||
mManager.updateProperties(view, buildStyles("textAlign", null, "textAlignVertical", null));
|
||||
assertThat(view.getGravity()).isEqualTo(defaultGravity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxLength() {
|
||||
ReactEditText view = mManager.createViewInstance(mThemedContext);
|
||||
InputFilter[] filters = new InputFilter[] { new InputFilter.AllCaps() };
|
||||
InputFilter[] filters = new InputFilter[] {new InputFilter.AllCaps()};
|
||||
view.setFilters(filters);
|
||||
mManager.setMaxLength(view, null);
|
||||
assertThat(view.getFilters()).isEqualTo(filters);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.textinput;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
@@ -40,16 +39,13 @@ import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Tests for TextInput.
|
||||
*/
|
||||
/** Tests for TextInput. */
|
||||
@PrepareForTest({Arguments.class, ReactChoreographer.class})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class TextInputTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
private ArrayList<ChoreographerCompat.FrameCallback> mPendingChoreographerCallbacks;
|
||||
|
||||
@@ -58,25 +54,30 @@ public class TextInputTest {
|
||||
PowerMockito.mockStatic(Arguments.class, ReactChoreographer.class);
|
||||
|
||||
ReactChoreographer choreographerMock = mock(ReactChoreographer.class);
|
||||
PowerMockito.when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(Arguments.createMap())
|
||||
.thenAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new JavaOnlyMap();
|
||||
}
|
||||
});
|
||||
PowerMockito.when(ReactChoreographer.getInstance()).thenReturn(choreographerMock);
|
||||
|
||||
mPendingChoreographerCallbacks = new ArrayList<>();
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
mPendingChoreographerCallbacks
|
||||
.add((ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
}).when(choreographerMock).postFrameCallback(
|
||||
any(ReactChoreographer.CallbackType.class),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
doAnswer(
|
||||
new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
mPendingChoreographerCallbacks.add(
|
||||
(ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.when(choreographerMock)
|
||||
.postFrameCallback(
|
||||
any(ReactChoreographer.CallbackType.class),
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,16 +94,10 @@ public class TextInputTest {
|
||||
textInputTag,
|
||||
ReactTextInputManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of(
|
||||
ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));
|
||||
JavaOnlyMap.of(ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));
|
||||
|
||||
uiManager.manageChildren(
|
||||
rootTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(textInputTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
rootTag, null, null, JavaOnlyArray.of(textInputTag), JavaOnlyArray.of(0), null);
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingChoreographerCallbacks();
|
||||
@@ -127,16 +122,10 @@ public class TextInputTest {
|
||||
textInputTag,
|
||||
ReactTextInputManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of(
|
||||
ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));
|
||||
JavaOnlyMap.of(ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));
|
||||
|
||||
uiManager.manageChildren(
|
||||
rootTag,
|
||||
null,
|
||||
null,
|
||||
JavaOnlyArray.of(textInputTag),
|
||||
JavaOnlyArray.of(0),
|
||||
null);
|
||||
rootTag, null, null, JavaOnlyArray.of(textInputTag), JavaOnlyArray.of(0), null);
|
||||
uiManager.onBatchComplete();
|
||||
executePendingChoreographerCallbacks();
|
||||
|
||||
@@ -172,12 +161,12 @@ public class TextInputTest {
|
||||
|
||||
public UIManagerModule getUIManagerModule() {
|
||||
ReactApplicationContext reactContext = ReactTestHelper.createCatalystContextForTest();
|
||||
List<ViewManager> viewManagers = Arrays.asList(
|
||||
new ViewManager[] {
|
||||
new ReactTextInputManager(),
|
||||
});
|
||||
UIManagerModule uiManagerModule =
|
||||
new UIManagerModule(reactContext, viewManagers, 0);
|
||||
List<ViewManager> viewManagers =
|
||||
Arrays.asList(
|
||||
new ViewManager[] {
|
||||
new ReactTextInputManager(),
|
||||
});
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(reactContext, viewManagers, 0);
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* <p>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.react.views.view;
|
||||
|
||||
import android.graphics.PixelFormat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import android.graphics.PixelFormat;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -16,17 +16,12 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Based on Fresco's DrawableUtilsTest (https://github.com/facebook/fresco).
|
||||
*/
|
||||
/** Based on Fresco's DrawableUtilsTest (https://github.com/facebook/fresco). */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ColorUtilTest {
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@Rule public PowerMockRule rule = new PowerMockRule();
|
||||
|
||||
@Test
|
||||
public void testMultiplyColorAlpha() {
|
||||
|
||||
@@ -10,7 +10,7 @@ package org.mockito.configuration;
|
||||
/**
|
||||
* Disables the Mockito cache to prevent Mockito & Robolectric bugs.
|
||||
*
|
||||
* Mockito loads this with reflection, so this class might appear unused.
|
||||
* <p>Mockito loads this with reflection, so this class might appear unused.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class MockitoConfiguration extends DefaultMockitoConfiguration {
|
||||
|
||||
Reference in New Issue
Block a user