-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
1,484 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...src/androidTest/java/com/w3engineers/unicef/telemesh/ui/aboutus/AboutUsViewModelTest.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,72 @@ | ||
package com.w3engineers.unicef.telemesh.ui.aboutus; | ||
|
||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import com.w3engineers.unicef.telemesh.BuildConfig; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
/* | ||
* ============================================================================ | ||
* Copyright (C) 2019 W3 Engineers Ltd - All Rights Reserved. | ||
* Unauthorized copying of this file, via any medium is strictly prohibited | ||
* Proprietary and confidential | ||
* ============================================================================ | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class AboutUsViewModelTest { | ||
|
||
private AboutUsViewModel SUT; | ||
|
||
@Rule | ||
public ActivityTestRule<AboutUsActivity> rule = new ActivityTestRule<>(AboutUsActivity.class); | ||
|
||
@Before | ||
public void setUp() { | ||
SUT = new AboutUsViewModel(rule.getActivity().getApplication()); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
@Test | ||
public void getAppVersion_matched_useValidBuildVersion() { | ||
addDelay(500); | ||
String buildVersion = "Version:" + BuildConfig.VERSION_NAME; | ||
assertEquals(SUT.getAppVersion(), buildVersion); | ||
addDelay(1000); | ||
} | ||
|
||
/*@Test | ||
public void getAppVersion_notMatched_useEmptyBuildVersion() { | ||
addDelay(500); | ||
String buildVersion = "Version:" + ""; | ||
assertNotEquals(SUT.getAppVersion(), buildVersion); | ||
addDelay(1000); | ||
} | ||
@Test | ||
public void getAppVersion_success_useNullBuildVersion() { | ||
addDelay(500); | ||
String buildVersion = "Version:" + null; | ||
assertNotEquals(SUT.getAppVersion(), buildVersion); | ||
addDelay(1000); | ||
}*/ | ||
|
||
private void addDelay(int i) { | ||
try { | ||
Thread.sleep(i); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
app/src/androidTest/java/com/w3engineers/unicef/telemesh/ui/chat/ChatViewModelTest.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,128 @@ | ||
package com.w3engineers.unicef.telemesh.ui.chat; | ||
|
||
import androidx.paging.PagedList; | ||
import androidx.room.Room; | ||
import androidx.test.rule.ActivityTestRule; | ||
|
||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/* | ||
* ============================================================================ | ||
* Copyright (C) 2019 W3 Engineers Ltd - All Rights Reserved. | ||
* Unauthorized copying of this file, via any medium is strictly prohibited | ||
* Proprietary and confidential | ||
* ============================================================================ | ||
*/ | ||
|
||
/*@RunWith(AndroidJUnit4.class) | ||
public class ChatViewModelTest { | ||
@Rule | ||
public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class); | ||
private AppDatabase appDatabase; | ||
private ChatViewModel SUT; | ||
private RandomEntityGenerator randomEntityGenerator; | ||
private UserDataSource userDataSource; | ||
private MessageSourceData messageSourceData; | ||
private Context mContext; | ||
private String userAddress = "0x3b52d4e229fd5396f468522e68f17cfe471b2e03"; | ||
@Before | ||
public void setUp() { | ||
mContext = InstrumentationRegistry.getContext(); | ||
randomEntityGenerator = new RandomEntityGenerator(); | ||
appDatabase = Room.inMemoryDatabaseBuilder(mContext, | ||
AppDatabase.class).allowMainThreadQueries().build(); | ||
userDataSource = UserDataSource.getInstance(appDatabase.userDao()); | ||
messageSourceData = MessageSourceData.getInstance(appDatabase.messageDao()); | ||
userDataSource = UserDataSource.getInstance(); | ||
messageSourceData = MessageSourceData.getInstance(); | ||
if (SharedPref.getSharedPref(mContext).read(Constants.preferenceKey.MY_USER_ID).isEmpty()) { | ||
SharedPref.getSharedPref(mContext).write(Constants.preferenceKey.MY_USER_ID, userAddress); | ||
} | ||
SUT = new ChatViewModel(rule.getActivity().getApplication()); | ||
} | ||
@Test | ||
public void testMessageSetAndGet_getMessageObject_setMessage() { | ||
addDelay(5000); | ||
try { | ||
UserEntity userEntity = randomEntityGenerator.createUserEntityWithId(); | ||
userDataSource.insertOrUpdateData(userEntity); | ||
String message = "Hi"; | ||
if (userEntity.getMeshId() != null) { | ||
SUT.sendMessage(userEntity.getMeshId(), message, true); | ||
} | ||
addDelay(700); | ||
TestObserver<List<ChatEntity>> listTestObserver = LiveDataTestUtil.testObserve(SUT.getAllMessage(userEntity.getMeshId())); | ||
addDelay(700); | ||
SUT.prepareDateSpecificChat(listTestObserver.observedvalues.get(0)); | ||
TestObserver<PagedList<ChatEntity>> testObserver = LiveDataTestUtil.testObserve(SUT.getChatEntityWithDate()); | ||
addDelay(700); | ||
assertThat(testObserver.observedvalues.get(0).size(), greaterThan(listTestObserver.observedvalues.get(0).size())); | ||
addDelay(700); | ||
assertThat(((MessageEntity) listTestObserver.observedvalues.get(0).get(0)).getMessage(), is(message)); | ||
ChatEntity receiverChat = randomEntityGenerator.createReceiverChatEntity(userEntity.getMeshId()); | ||
messageSourceData.insertOrUpdateData(receiverChat); | ||
addDelay(700); | ||
SUT.updateAllMessageStatus(userEntity.getMeshId()); | ||
addDelay(700); | ||
ChatEntity retrieveReceiverChat = messageSourceData.getMessageEntityById(receiverChat.getMessageId()); | ||
assertThat(retrieveReceiverChat.getStatus(), is(Constants.MessageStatus.STATUS_READ)); | ||
userEntity.setOnlineStatus(Constants.UserStatus.OFFLINE); | ||
userDataSource.insertOrUpdateData(userEntity); | ||
//TestObserver<UserEntity> entityTestObserver = LiveDataTestUtil.testObserve(SUT.getUserById(userEntity.getMeshId())); | ||
addDelay(2000); | ||
assertFalse(userEntity.getOnlineStatus() > Constants.UserStatus.OFFLINE); | ||
addDelay(1000); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
private void addDelay(long time) { | ||
try { | ||
Thread.sleep(time); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
@After | ||
public void tearDown() { | ||
appDatabase.close(); | ||
} | ||
}*/ |
80 changes: 80 additions & 0 deletions
80
...droidTest/java/com/w3engineers/unicef/telemesh/ui/createuser/CreateUserViewModelTest.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,80 @@ | ||
package com.w3engineers.unicef.telemesh.ui.createuser; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
import androidx.test.InstrumentationRegistry; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import com.w3engineers.unicef.telemesh.data.helper.constants.Constants; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/* | ||
* ============================================================================ | ||
* Copyright (C) 2019 W3 Engineers Ltd - All Rights Reserved. | ||
* Unauthorized copying of this file, via any medium is strictly prohibited | ||
* Proprietary and confidential | ||
* ============================================================================ | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class CreateUserViewModelTest { | ||
|
||
private SharedPreferences sharedPreferences; | ||
private CreateUserViewModel SUT; | ||
|
||
@Rule | ||
public ActivityTestRule<CreateUserActivity> rule = new ActivityTestRule<>(CreateUserActivity.class); | ||
|
||
@Before | ||
public void setUp() { | ||
Context context = InstrumentationRegistry.getTargetContext(); | ||
SUT = new CreateUserViewModel(rule.getActivity().getApplication()); | ||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
|
||
@Test | ||
public void storeData_storeNameNull_getNameNull() { | ||
String firstName = null; | ||
String lastName = null; | ||
int imageIndex = -1; | ||
|
||
SUT.setImageIndex(imageIndex); | ||
// SUT.storeData(firstName); | ||
|
||
checkValues(firstName, imageIndex); | ||
} | ||
|
||
@Test | ||
public void isNameValid_true_setValidString() { | ||
String firstName = "Daniel"; | ||
assertTrue(SUT.isNameValid(firstName)); | ||
} | ||
|
||
@Test | ||
public void storeData_true_setValidData() { | ||
String firstName = "Daniel"; | ||
String password = "mesh_123"; | ||
assertTrue(SUT.storeData(firstName)); | ||
} | ||
|
||
private void checkValues(String firstName, int imageIndex) { | ||
assertEquals(firstName, sharedPreferences.getString(Constants.preferenceKey.USER_NAME, null)); | ||
assertEquals(imageIndex, sharedPreferences.getInt(Constants.preferenceKey.IMAGE_INDEX, -1)); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...oidTest/java/com/w3engineers/unicef/telemesh/ui/editprofile/EditProfileViewModelTest.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,70 @@ | ||
package com.w3engineers.unicef.telemesh.ui.editprofile; | ||
|
||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/* | ||
* ============================================================================ | ||
* Copyright (C) 2019 W3 Engineers Ltd - All Rights Reserved. | ||
* Unauthorized copying of this file, via any medium is strictly prohibited | ||
* Proprietary and confidential | ||
* ============================================================================ | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class EditProfileViewModelTest { | ||
|
||
private EditProfileViewModel SUT; | ||
|
||
@Rule | ||
public ActivityTestRule<EditProfileActivity> rule = new ActivityTestRule<>(EditProfileActivity.class); | ||
|
||
@Before | ||
public void setUp() { | ||
SUT = new EditProfileViewModel(rule.getActivity().getApplication()); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
@Test | ||
public void storeData_storeNameNull_getNameNull() { | ||
String firstName = "Daniel"; | ||
int imageIndex = -1; | ||
|
||
SUT.setImageIndex(imageIndex); | ||
|
||
assertTrue(SUT.storeData(firstName)); | ||
} | ||
|
||
@Test | ||
public void isNameValid_true_setValidString() { | ||
String firstName = "Daniel"; | ||
assertTrue(SUT.isNameValid(firstName)); | ||
|
||
addDelay(500); | ||
|
||
SUT.sendUserInfoToAll(); | ||
|
||
addDelay(2000); | ||
|
||
assertTrue(true); | ||
} | ||
|
||
private void addDelay(long time) { | ||
try { | ||
Thread.sleep(time); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Oops, something went wrong.