File tree Expand file tree Collapse file tree
ReactAndroid/src/androidTest/java/com/facebook/react/testing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) 2014-present, Facebook, Inc.
3+ * All rights reserved.
4+ * This source code is licensed under the BSD-style license found in the
5+ * LICENSE file in the root directory of this source tree. An additional grant
6+ * of patent rights can be found in the PATENTS file in the same directory.
7+ */
8+
9+ package com .facebook .react .testing ;
10+
11+ import java .util .ArrayList ;
12+ import java .util .List ;
13+ import java .util .concurrent .CountDownLatch ;
14+ import java .util .concurrent .TimeUnit ;
15+
16+ import com .facebook .react .bridge .BaseJavaModule ;
17+ import com .facebook .react .bridge .ReactMethod ;
18+
19+ /**
20+ * Native module provides single method {@link #record} which records its single int argument
21+ * in calls array
22+ */
23+ public class IntRecordingModule extends BaseJavaModule {
24+
25+ private final List <Integer > mCalls = new ArrayList <>();
26+ private final CountDownLatch mCountDownLatch = new CountDownLatch (1 );
27+
28+ @ Override
29+ public String getName () {
30+ return "Recording" ;
31+ }
32+
33+ @ ReactMethod
34+ public void record (int i ) {
35+ mCalls .add (i );
36+ mCountDownLatch .countDown ();
37+ }
38+
39+ public void reset () {
40+ mCalls .clear ();
41+ }
42+
43+ public List <Integer > getCalls () {
44+ return mCalls ;
45+ }
46+
47+ public void waitForFirstCall () {
48+ try {
49+ if (!mCountDownLatch .await (15000 , TimeUnit .MILLISECONDS )) {
50+ throw new RuntimeException ("Timed out waiting for first call" );
51+ }
52+ } catch (InterruptedException e ) {
53+ throw new RuntimeException (e );
54+ }
55+ }
56+ }
Original file line number Diff line number Diff line change 1414import java .util .concurrent .Semaphore ;
1515import java .util .concurrent .TimeUnit ;
1616
17+ import android .app .Application ;
1718import android .support .test .InstrumentationRegistry ;
1819import android .test .AndroidTestCase ;
1920import android .view .View ;
2728import com .facebook .react .bridge .LifecycleEventListener ;
2829import com .facebook .react .bridge .SoftAssertions ;
2930import com .facebook .react .bridge .UiThreadUtil ;
31+ import com .facebook .react .common .ApplicationHolder ;
3032import com .facebook .react .common .futures .SimpleSettableFuture ;
3133import com .facebook .react .modules .core .Timing ;
3234
@@ -155,6 +157,7 @@ public void run() {
155157 mBridgeIdleSignaler = new ReactBridgeIdleSignaler ();
156158 mInstance .addBridgeIdleDebugListener (mBridgeIdleSignaler );
157159 getContext ().initializeWithInstance (mInstance );
160+ ApplicationHolder .setApplication ((Application ) getContext ().getApplicationContext ());
158161 setupEvent .occur ();
159162 }
160163 });
You can’t perform that action at this time.
0 commit comments