99import com .firebase .ui .auth .testhelpers .TestConstants ;
1010import com .firebase .ui .auth .testhelpers .TestHelper ;
1111import com .firebase .ui .auth .viewmodel .email .RecoverPasswordHandler ;
12+ import com .google .firebase .auth .ActionCodeSettings ;
1213import com .google .firebase .auth .EmailAuthProvider ;
1314import com .google .firebase .auth .FirebaseAuth ;
1415
@@ -39,6 +40,8 @@ public class RecoverPasswordHandlerTest {
3940
4041 private RecoverPasswordHandler mHandler ;
4142
43+ private ActionCodeSettings mPasswordResetSettings ;
44+
4245 @ Before
4346 public void setUp () {
4447 TestHelper .initialize ();
@@ -49,6 +52,12 @@ public void setUp() {
4952 FlowParameters testParams = TestHelper .getFlowParameters (Collections .singletonList (
5053 EmailAuthProvider .PROVIDER_ID ));
5154 mHandler .initializeForTesting (testParams , mMockAuth , null , null );
55+
56+ mPasswordResetSettings = ActionCodeSettings .newBuilder ()
57+ .setAndroidPackageName ("com.firebase.uidemo" , true , null )
58+ .setHandleCodeInApp (true )
59+ .setUrl ("https://google.com" )
60+ .build ();
5261 }
5362
5463 @ Test
@@ -59,7 +68,7 @@ public void testReset_sendsRecoverEmail() {
5968
6069 // Begin observation, then send the email
6170 mHandler .getOperation ().observeForever (mObserver );
62- mHandler .startReset (TestConstants .EMAIL );
71+ mHandler .startReset (TestConstants .EMAIL , null );
6372
6473 // Should get in-progress resource
6574 verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
@@ -79,7 +88,7 @@ public void testReset_propagatesFailure() {
7988
8089 // Begin observation, then send the email
8190 mHandler .getOperation ().observeForever (mObserver );
82- mHandler .startReset (TestConstants .EMAIL );
91+ mHandler .startReset (TestConstants .EMAIL , null );
8392
8493 // Should get in-progress resource
8594 verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
@@ -91,4 +100,43 @@ public void testReset_propagatesFailure() {
91100 verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isFailure ()));
92101 }
93102
103+ @ Test
104+ public void testReset_sendsCustomRecoverEmail () {
105+ // Send password email succeeds
106+ when (mMockAuth .sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings ))
107+ .thenReturn (AutoCompleteTask .<Void >forSuccess (null ));
108+
109+ // Begin observation, then send the email
110+ mHandler .getOperation ().observeForever (mObserver );
111+ mHandler .startReset (TestConstants .EMAIL , mPasswordResetSettings );
112+
113+ // Should get in-progress resource
114+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
115+
116+ // Firebase auth should be called
117+ verify (mMockAuth ).sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings );
118+
119+ // Should get the success resource
120+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isSuccess ()));
121+ }
122+
123+ @ Test
124+ public void testCustomReset_propagatesFailure () {
125+ // Send password email fails
126+ when (mMockAuth .sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings ))
127+ .thenReturn (AutoCompleteTask .<Void >forFailure (new Exception ("FAILED" )));
128+
129+ // Begin observation, then send the email
130+ mHandler .getOperation ().observeForever (mObserver );
131+ mHandler .startReset (TestConstants .EMAIL , mPasswordResetSettings );
132+
133+ // Should get in-progress resource
134+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isLoading ()));
135+
136+ // Firebase auth should be called
137+ verify (mMockAuth ).sendPasswordResetEmail (TestConstants .EMAIL , mPasswordResetSettings );
138+
139+ // Should get the success resource
140+ verify (mObserver ).onChanged (argThat (ResourceMatchers .<String >isFailure ()));
141+ }
94142}
0 commit comments