-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test cases added * test case change from mainmodel to mainviewmodel * null string, stored in database, invalid new username format test case added * Sprint2: Implement test case --------- Co-authored-by: Sam-zzZ <[email protected]>
- Loading branch information
1 parent
3d9498e
commit 523a8f4
Showing
2 changed files
with
152 additions
and
22 deletions.
There are no files selected for viewing
146 changes: 138 additions & 8 deletions
146
Project/Sprint2/app/src/androidTest/java/com/example/sprint1/ExampleInstrumentedTest.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 |
---|---|---|
@@ -1,26 +1,156 @@ | ||
package com.example.sprint1; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
|
||
import com.example.sprint1.viewmodel.MainViewModel; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
private static final MainViewModel mainViewModel = new MainViewModel(); | ||
|
||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.example.sprint1", appContext.getPackageName()); | ||
} | ||
|
||
@Test | ||
public void testUserSignUpWithExistingUsername() { | ||
mainViewModel.userSignUp("testUser", "testPassword", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testUserSignInWithCorrectCredentials() { | ||
mainViewModel.userSignIn("tianrui", "1", Assert::assertTrue); | ||
} | ||
|
||
@Test | ||
public void testUserSignInWithIncorrectPassword() { | ||
mainViewModel.userSignIn("tianrui", "2", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testAddDestinationWithValidData() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.addDestination("Paris", "01/01/2023", "01/11/2023", Assert::assertTrue); | ||
} | ||
|
||
@Test | ||
public void testAddDestinationWithAdditionalValidData() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.addDestination("New York", "01/04/2023", "01/06/2023", Assert::assertTrue); | ||
} | ||
|
||
@Test | ||
public void testAddDestinationWithDuplicateLocation() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.addDestination("Atlanta", "01/01/2023", "01/11/2023", Assert::assertTrue); | ||
} | ||
|
||
@Test | ||
public void testGetDestinationsWithExistingDestinations() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.getDestinations(result -> assertTrue(result.containsKey("Paris"))); | ||
} | ||
|
||
@Test | ||
public void testGetDestinationsWithNoDestinations() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.getDestinations(Assert::assertNull); | ||
} | ||
|
||
@Test | ||
public void testSetVacationWithValidDatesAndDuration() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.setVacation("01/01/2023", "01/10/2023", "10", Assert::assertTrue); | ||
mainViewModel.getVacation(result -> { | ||
assertEquals("01/01/2023", result.get("startDate")); | ||
assertEquals("01/10/2023", result.get("endDate")); | ||
assertEquals("10", result.get("duration")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testSetVacationWithMismatchedDuration() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.setVacation("01/10/2023", "01/01/2023", "5", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testCalculateOccupiedDaysWithValidVacationAndDestinations() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.setVacation("01/01/2023", "01/21/2023", "21", Assert::assertTrue); | ||
mainViewModel.addDestination("Paris", "01/01/2023", "01/11/2023", Assert::assertTrue); | ||
} | ||
|
||
@Test | ||
public void testCalculateOccupiedDaysWithNoOverlap() throws InterruptedException { | ||
CountDownLatch latch = new CountDownLatch(1); | ||
mainViewModel.userSignIn("testUser", "testPassword", result -> { | ||
assertTrue(result); | ||
latch.countDown(); | ||
}); | ||
assertTrue(latch.await(5, TimeUnit.SECONDS)); | ||
|
||
mainViewModel.setVacation("01/01/2023", "01/30/2023", "30", Assert::assertTrue); | ||
mainViewModel.addDestination("Paris", "01/15/2023", "01/20/2023", Assert::assertTrue); | ||
} | ||
|
||
@Test | ||
public void testLogTravelWithEmptyLocation() { | ||
mainViewModel.addDestination("", "01/01/2023", "01/10/2023", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testLogTravelEntryStoredInDatabase() { | ||
mainViewModel.userSignIn("testUser", "testPassword", Assert::assertTrue); | ||
mainViewModel.getDestinations(result -> { | ||
assertNotNull(result); | ||
assertTrue(result.containsKey("TestLocation")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testAccountCreationWithWhitespaceOnlyInput() { | ||
mainViewModel.userSignUp(" ", "validPassword", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testAccountCreationWithNullInput() { | ||
mainViewModel.userSignUp(null, "validPassword", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testAccountCreationWithEmptyStringInput() { | ||
mainViewModel.userSignUp("", "validPassword", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testAccountLoginWithWhitespaceOnlyInput() { | ||
mainViewModel.userSignIn(" ", "validPassword", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testAccountLoginWithNullInput() { | ||
mainViewModel.userSignIn(null, "validPassword", Assert::assertFalse); | ||
} | ||
|
||
@Test | ||
public void testAccountLoginWithEmptyStringInput() { | ||
mainViewModel.userSignIn("", "validPassword", Assert::assertFalse); | ||
} | ||
} |
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