-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Mofazzal874/Amit
Amit
- Loading branch information
Showing
5 changed files
with
119 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/androidTest/java/com/example/projecto/activities/AddressActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.example.projecto.activities; | ||
|
||
import androidx.test.espresso.intent.Intents; | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import com.example.projecto.R; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.intent.Intents.intended; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class AddressActivityTest { | ||
|
||
@Rule | ||
public ActivityScenarioRule<AddressActivity> activityRule = | ||
new ActivityScenarioRule<>(AddressActivity.class); | ||
|
||
@Rule | ||
public FirebaseAuthRule firebaseAuthRule = new FirebaseAuthRule(); | ||
|
||
@Before | ||
public void setUp() { | ||
Intents.init(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
Intents.release(); | ||
} | ||
|
||
@Test | ||
public void testPaymentButton_opensPaymentActivity() { | ||
// Perform click on paymentBtn | ||
onView(withId(R.id.payment_btn)).perform(click()); | ||
|
||
// Verify that the PaymentActivity is launched | ||
intended(hasComponent(PaymentActivity.class.getName())); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/androidTest/java/com/example/projecto/activities/FirebaseAuthRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.example.projecto.activities; | ||
|
||
import com.google.firebase.auth.FirebaseAuth; | ||
import com.google.firebase.auth.FirebaseUser; | ||
|
||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FirebaseAuthRule implements TestRule { | ||
|
||
private final FirebaseAuth mockAuth; | ||
private final FirebaseUser mockUser; | ||
|
||
public FirebaseAuthRule() { | ||
mockAuth = mock(FirebaseAuth.class); | ||
mockUser = mock(FirebaseUser.class); | ||
when(mockAuth.getCurrentUser()).thenReturn(mockUser); | ||
when(mockUser.getUid()).thenReturn("testUid"); | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
// Inject the mock FirebaseAuth instance | ||
AddressActivity.setFirebaseAuth(mockAuth); | ||
|
||
// Execute the test | ||
base.evaluate(); | ||
|
||
// Clean up after test execution | ||
AddressActivity.setFirebaseAuth(null); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters