mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
clean up tests
This commit is contained in:
parent
88854a3b59
commit
5c3475ed64
36 changed files with 355 additions and 1543 deletions
32
.github/workflows/android.yml
vendored
32
.github/workflows/android.yml
vendored
|
|
@ -37,7 +37,37 @@ jobs:
|
|||
source: "Habitica/google-services.json.example"
|
||||
target: "Habitica/google-services.json"
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew assembleDebug -PdisablePreDex
|
||||
run: ./gradlew assembleProdDebug -PdisablePreDex
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: gradle
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
- name: copy properties file
|
||||
uses: canastro/copy-file-action@master
|
||||
with:
|
||||
source: "habitica.properties.example"
|
||||
target: "habitica.properties"
|
||||
- name: copy resources file
|
||||
uses: canastro/copy-file-action@master
|
||||
with:
|
||||
source: "habitica.resources.example"
|
||||
target: "habitica.resources"
|
||||
- name: copy google services file
|
||||
uses: canastro/copy-file-action@master
|
||||
with:
|
||||
source: "Habitica/google-services.json.example"
|
||||
target: "Habitica/google-services.json"
|
||||
- name: Run Tests
|
||||
run: ./gradlew testProdDebugUnitTest
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ dependencies {
|
|||
|
||||
//Dependency Injection
|
||||
implementation 'com.google.dagger:dagger:2.38'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
kapt 'com.google.dagger:dagger-compiler:2.38'
|
||||
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
|
||||
compileOnly 'com.github.pengrad:jdk9-deps:1.0'
|
||||
|
|
@ -84,17 +85,13 @@ dependencies {
|
|||
implementation("io.coil-kt:coil:1.2.2")
|
||||
implementation("io.coil-kt:coil-gif:1.2.2")
|
||||
//Tests
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation(platform('org.junit:junit-bom:5.8.0'))
|
||||
testImplementation('org.junit.jupiter:junit-jupiter')
|
||||
testImplementation 'androidx.test:core:1.4.0'
|
||||
testImplementation "com.google.truth:truth:1.0.1"
|
||||
testImplementation 'org.assertj:assertj-core:2.6.0'
|
||||
testImplementation 'org.robolectric:robolectric:4.6.1'
|
||||
testImplementation 'org.robolectric:shadows-multidex:4.6.1'
|
||||
testImplementation 'org.mockito:mockito-core:2.25.0'
|
||||
testImplementation 'org.powermock:powermock-api-mockito2:1.7.0'
|
||||
testImplementation 'org.powermock:powermock-module-junit4-rule-agent:1.7.0'
|
||||
testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.0'
|
||||
testImplementation 'org.powermock:powermock-module-junit4:1.7.0'
|
||||
testImplementation "io.mockk:mockk:1.12.0"
|
||||
testImplementation "io.mockk:mockk-android:1.12.0"
|
||||
testImplementation 'io.kotest:kotest-assertions-core:4.6.2'
|
||||
|
||||
//Leak Detection
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
|
||||
//Push Notifications
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.habitrpg.android.habitica.data.ApiClient
|
|||
import com.habitrpg.android.habitica.events.ConsumablePurchasedEvent
|
||||
import com.habitrpg.android.habitica.events.UserSubscribedEvent
|
||||
import com.habitrpg.android.habitica.helpers.PurchaseTypes
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.json.JSONObject
|
||||
|
|
@ -120,6 +121,7 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
outputMap[key] = value
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
return outputMap
|
||||
}
|
||||
|
|
|
|||
|
|
@ -404,6 +404,7 @@ object DeviceName {
|
|||
try {
|
||||
return DeviceInfo(JSONObject(savedJson))
|
||||
} catch (e: JSONException) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -443,6 +444,7 @@ object DeviceName {
|
|||
i++
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
return if (codename == Build.DEVICE && Build.MODEL == model) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class SoundFile(val theme: String, private val fileName: String) : MediaPlayer.O
|
|||
isPlaying = true
|
||||
m.start()
|
||||
} catch (e: Exception) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.text.Spanned
|
|||
import androidx.annotation.StringDef
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.BaseMainObject
|
||||
import com.habitrpg.android.habitica.models.Tag
|
||||
import com.habitrpg.android.habitica.models.user.Stats
|
||||
|
|
@ -345,6 +346,7 @@ open class Task : RealmObject, BaseMainObject, Parcelable {
|
|||
i += 1
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
this.weeksOfMonth = weeksOfMonth.toList()
|
||||
|
|
@ -373,6 +375,7 @@ open class Task : RealmObject, BaseMainObject, Parcelable {
|
|||
i += 1
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
this.daysOfMonth = daysOfMonth
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.view.MenuItem
|
|||
import android.widget.TextView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.ui.helpers.setMarkdown
|
||||
import okhttp3.*
|
||||
import java.io.BufferedReader
|
||||
|
|
@ -24,6 +25,7 @@ class GuidelinesActivity : BaseActivity() {
|
|||
val request = Request.Builder().url("https://s3.amazonaws.com/habitica-assets/mobileApp/endpoint/community-guidelines.md").build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ class LoginActivity : BaseActivity(), Consumer<UserAuthResponse> {
|
|||
override fun onCancel() { /* no-on */ }
|
||||
|
||||
override fun onError(exception: FacebookException) {
|
||||
RxErrorHandler.reportError(exception)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
try {
|
||||
launchTrace = FirebasePerformance.getInstance().newTrace("MainActivityLaunch")
|
||||
} catch (_: IllegalStateException) {
|
||||
} catch (e: IllegalStateException) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
launchTrace?.start()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -756,6 +757,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
startActivity(intent)
|
||||
}
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.google.gson.JsonDeserializer
|
|||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParseException
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.inventory.Customization
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
|
|
@ -105,6 +106,7 @@ class CustomizationDeserializer : JsonDeserializer<List<Customization>> {
|
|||
customization.availableUntil = format.parse(setInfo.get("availableUntil").asString)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
RxErrorHandler.reportError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class BaseTestCase {
|
||||
|
||||
@Before
|
||||
public void initMocks() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.habitrpg.android.habitica
|
||||
|
||||
import io.mockk.MockKAnnotations
|
||||
import org.junit.Before
|
||||
|
||||
class BaseTestCase {
|
||||
@Before
|
||||
fun initMocks() {
|
||||
MockKAnnotations.init(this, relaxed = true)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import com.habitrpg.android.habitica.modules.RepositoryModule;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import dagger.Provides;
|
||||
import io.realm.Realm;
|
||||
|
||||
class TestRepositoryModule extends RepositoryModule {
|
||||
|
||||
@Provides
|
||||
@Override
|
||||
public Realm providesRealm() {
|
||||
return Mockito.mock(Realm.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.habitrpg.android.habitica
|
||||
|
||||
import com.habitrpg.android.habitica.modules.RepositoryModule
|
||||
import dagger.Provides
|
||||
import io.mockk.mockk
|
||||
import io.realm.Realm
|
||||
|
||||
internal class TestRepositoryModule : RepositoryModule() {
|
||||
@Provides
|
||||
override fun providesRealm(): Realm {
|
||||
return mockk()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.api;
|
||||
//
|
||||
//
|
||||
//import com.habitrpg.android.habitica.data.implementation.ApiClientImpl;
|
||||
//import com.habitrpg.android.habitica.helpers.NotificationsManager;
|
||||
//import com.habitrpg.android.habitica.proxy.implementation.EmptyAnalyticsManager;
|
||||
//import com.habitrpg.android.habitica.data.ApiClient;
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.models.user.User;
|
||||
//import com.habitrpg.android.habitica.models.auth.UserAuthResponse;
|
||||
//
|
||||
//import org.junit.After;
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import org.robolectric.RuntimeEnvironment;
|
||||
//import org.robolectric.shadows.ShadowApplication;
|
||||
//
|
||||
//import android.content.Context;
|
||||
//
|
||||
//import java.security.InvalidParameterException;
|
||||
//import java.util.UUID;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import rx.Scheduler;
|
||||
//import rx.android.plugins.RxAndroidPlugins;
|
||||
//import rx.android.schedulers.AndroidSchedulers;
|
||||
//
|
||||
//import rx.observers.TestSubscriber;
|
||||
//import rx.plugins.RxJavaPlugins;
|
||||
//import rx.plugins.RxJavaSchedulersHook;
|
||||
//
|
||||
//import static org.junit.Assert.assertTrue;
|
||||
//
|
||||
//import rx.plugins.RxJavaTestPlugins;
|
||||
//import rx.schedulers.Schedulers;
|
||||
//
|
||||
//
|
||||
//public class BaseAPITests {
|
||||
//
|
||||
// public ApiClient apiClient;
|
||||
// public HostConfig hostConfig;
|
||||
//
|
||||
// public String username;
|
||||
// public final String password = "password";
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() {
|
||||
// if (BuildConfig.BASE_URL.contains("habitica.com")) {
|
||||
// throw new InvalidParameterException("Can't test against production server.");
|
||||
// }
|
||||
//
|
||||
// RxJavaTestPlugins.resetPlugins();
|
||||
// RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() {
|
||||
// @Override
|
||||
// public Scheduler getIOScheduler() {
|
||||
// return AndroidSchedulers.mainThread();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// Context context = RuntimeEnvironment.application;
|
||||
// hostConfig = new HostConfig(BuildConfig.BASE_URL,
|
||||
// BuildConfig.PORT,
|
||||
// "",
|
||||
// "");
|
||||
// //apiClient = new ApiClientImpl(ApiClientImpl.createGsonFactory(), hostConfig, new EmptyCrashlyticsProxy(), new NotificationsManager(context), context);
|
||||
// //generateUser();
|
||||
// }
|
||||
//
|
||||
// public void generateUser() {
|
||||
// TestSubscriber<UserAuthResponse> testSubscriber = new TestSubscriber<>();
|
||||
// username = UUID.randomUUID().toString();
|
||||
// apiClient.registerUser(username, username+"@example.com", password, password)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
|
||||
// testSubscriber.assertCompleted();
|
||||
// UserAuthResponse response = testSubscriber.getOnNextEvents().get(0);
|
||||
// hostConfig.setUser(response.getId());
|
||||
// hostConfig.setApi(response.getApiToken() != null ? response.getApiToken() : response.getToken());
|
||||
// }
|
||||
//
|
||||
// public User getUser() {
|
||||
// TestSubscriber<User> userSubscriber = new TestSubscriber<>();
|
||||
//
|
||||
// apiClient.getUser()
|
||||
// .subscribe(userSubscriber);
|
||||
// userSubscriber.awaitTerminalEvent();
|
||||
// userSubscriber.assertNoErrors();
|
||||
// userSubscriber.assertCompleted();
|
||||
// User user = userSubscriber.getOnNextEvents().get(0);
|
||||
//
|
||||
// return user;
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void emptyTest() {
|
||||
// assertTrue(true);
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void tearDown() {
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.api;
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
//import com.habitrpg.android.habitica.models.social.Group;
|
||||
//import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
//
|
||||
//import org.junit.After;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.robolectric.RobolectricTestRunner;
|
||||
//import org.robolectric.annotation.Config;
|
||||
//
|
||||
//import android.os.Build;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import rx.observers.TestSubscriber;
|
||||
//
|
||||
//@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.M)
|
||||
//@RunWith(RobolectricTestRunner.class)
|
||||
//public class SocialAPITests extends BaseAPITests {
|
||||
//
|
||||
// List<String> messagesIDs;
|
||||
// String groupID;
|
||||
//
|
||||
// @Override
|
||||
// public void setUp() {
|
||||
// super.setUp();
|
||||
// groupID = null;
|
||||
// messagesIDs = new ArrayList<>();
|
||||
// }
|
||||
//
|
||||
// public void postMessage(String groupID, String messageSuffix) {
|
||||
// HashMap<String, String> messageObject = new HashMap<>();
|
||||
// messageObject.put("message", "Foo Bar"+messageSuffix);
|
||||
// TestSubscriber<PostChatMessageResult> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.postGroupChat(groupID, messageObject)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// PostChatMessageResult result = testSubscriber.getOnNextEvents().get(0);
|
||||
// messagesIDs.add(result.message.getId());
|
||||
// }
|
||||
//
|
||||
// /*@Test
|
||||
// public void shouldLoadTavernWithMessages() {
|
||||
// groupID = "habitrpg";
|
||||
// postMessage(groupID, "1");
|
||||
//
|
||||
// TestSubscriber<Group> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.getGroupData(groupID)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// testSubscriber.assertValueCount(1);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldLoadTavernChat() {
|
||||
// groupID = "habitrpg";
|
||||
// postMessage(groupID, "1");
|
||||
// postMessage(groupID, "2");
|
||||
//
|
||||
// TestSubscriber<List<ChatMessage>> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.listGroupChat(groupID)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// testSubscriber.assertValueCount(1);
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void tearDown() {
|
||||
// TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
|
||||
// for (String messageID : this.messagesIDs) {
|
||||
// apiClient.deleteMessage("habitrpg", messageID)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// }
|
||||
// super.tearDown();
|
||||
// }*/
|
||||
//}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.api;
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.models.Tag;
|
||||
//
|
||||
//import junit.framework.Assert;
|
||||
//
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.robolectric.RobolectricTestRunner;
|
||||
//import org.robolectric.annotation.Config;
|
||||
//
|
||||
//import android.os.Build;
|
||||
//
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//import rx.observers.TestSubscriber;
|
||||
//
|
||||
//@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.M)
|
||||
//@RunWith(RobolectricTestRunner.class)
|
||||
//public class TagAPITests extends BaseAPITests {
|
||||
//
|
||||
// /*@Test
|
||||
// public void shouldCreateTag() {
|
||||
// TestSubscriber<Tag> testSubscriber = new TestSubscriber<>();
|
||||
// Tag tag = new Tag();
|
||||
// tag.setName("foo");
|
||||
// apiClient.createTag(tag)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// testSubscriber.assertValueCount(1);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldUpdateTag() {
|
||||
// TestSubscriber<Tag> testSubscriber = new TestSubscriber<>();
|
||||
//
|
||||
// Tag t = new Tag();
|
||||
// String newname = "BAR";
|
||||
// t.setId(String.valueOf(UUID.randomUUID()));
|
||||
// t.setName(newname);
|
||||
//
|
||||
// //Attempt to update the test user's first tag
|
||||
// String testId = getUserData().getTags().get(0).getId();
|
||||
// apiClient.updateTag(testId,t)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// Assert.assertEquals(newname,testSubscriber.getOnNextEvents().get(0).getName());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldDeleteTag() {
|
||||
// TestSubscriber<Void> testSub = new TestSubscriber<>();
|
||||
//
|
||||
// String testId = getUserData().getTags().get(0).getId();
|
||||
// apiClient.deleteTag(testId)
|
||||
// .subscribe(testSub);
|
||||
// testSub.awaitTerminalEvent();
|
||||
// testSub.assertNoErrors();
|
||||
// testSub.assertCompleted();
|
||||
// }*/
|
||||
//
|
||||
//}
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.api;
|
||||
//
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.models.responses.TaskDirectionData;
|
||||
//import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
//import com.habitrpg.android.habitica.models.tasks.TaskList;
|
||||
//
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.robolectric.RobolectricTestRunner;
|
||||
//import org.robolectric.annotation.Config;
|
||||
//
|
||||
//import android.os.Build;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//import io.realm.RealmList;
|
||||
//import rx.observers.TestSubscriber;
|
||||
//
|
||||
//import static org.junit.Assert.assertEquals;
|
||||
//import static org.junit.Assert.assertTrue;
|
||||
//
|
||||
//@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.M)
|
||||
//@RunWith(RobolectricTestRunner.class)
|
||||
//public class TaskAPITests extends BaseAPITests {
|
||||
//
|
||||
// private Task habit1;
|
||||
// private Task daily1;
|
||||
// private Task todo1;
|
||||
// private Task reward1;
|
||||
//
|
||||
// @Override
|
||||
// public void setUp() {
|
||||
// super.setUp();
|
||||
// /*TestSubscriber<TaskList> oldTaskSubscriber = new TestSubscriber<>();
|
||||
// apiClient.getTasks()
|
||||
// .subscribe(oldTaskSubscriber);
|
||||
// oldTaskSubscriber.awaitTerminalEvent();
|
||||
// TaskList tasks = oldTaskSubscriber.getOnNextEvents().get(0);
|
||||
// for (Task task : tasks.tasks.values()) {
|
||||
// apiClient.deleteTask(task.getId()).subscribe(new TestSubscriber<>());
|
||||
// }
|
||||
//
|
||||
// List<Task> randomTasks = new ArrayList<>();
|
||||
// randomTasks.add(createRandomTask("1", "habit"));
|
||||
// habit1 = randomTasks.get(0);
|
||||
// randomTasks.add(createRandomTask("2", "habit"));
|
||||
// randomTasks.add(createRandomTask("3", "daily"));
|
||||
// daily1 = randomTasks.get(2);
|
||||
// randomTasks.add(createRandomTask("4", "daily"));
|
||||
// randomTasks.add(createRandomTask("5", "todo"));
|
||||
// todo1 = randomTasks.get(4);
|
||||
// randomTasks.add(createRandomTask("6", "todo"));
|
||||
// randomTasks.add(createRandomTask("7", "reward"));
|
||||
// reward1 = randomTasks.get(6);
|
||||
// randomTasks.add(createRandomTask("8", "reward"));
|
||||
// TestSubscriber<List<Task>> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.createTasks(randomTasks)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();*/
|
||||
// }
|
||||
//
|
||||
// private Task createRandomTask(String number, String type) {
|
||||
// Task task = new Task();
|
||||
// task.setId(String.valueOf(UUID.randomUUID()));
|
||||
// task.setText("task-"+number);
|
||||
// task.setType(type);
|
||||
// task.setTags(new RealmList<>());
|
||||
// task.setChecklist(new RealmList<>());
|
||||
// task.setReminders(new RealmList<>());
|
||||
// return task;
|
||||
// }
|
||||
//
|
||||
// /*@Test
|
||||
// public void shouldLoadAllTasksFromServer() {
|
||||
// TestSubscriber<TaskList> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.getTasks()
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// TaskList taskList = testSubscriber.getOnNextEvents().get(0);
|
||||
// assertEquals(8, taskList.tasks.size());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldBeAbleToScoreTaskUp() {
|
||||
// TestSubscriber<TaskDirectionData> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.postTaskDirection(habit1.getId(), "UP")
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// TaskDirectionData data = testSubscriber.getOnNextEvents().get(0);
|
||||
// assertTrue(data.getDelta() > 0);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldBeAbleToScoreTaskDown() {
|
||||
// TestSubscriber<TaskDirectionData> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.postTaskDirection(habit1.getId(), "DOWN")
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// TaskDirectionData data = testSubscriber.getOnNextEvents().get(0);
|
||||
// assertTrue(data.getDelta() < 0);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldBeAbleToDeleteATask() {
|
||||
// TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.deleteTask(habit1.getId())
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertCompleted();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// TestSubscriber<TaskList> newTaskListSubscriber = new TestSubscriber<>();
|
||||
// apiClient.getTasks().subscribe(newTaskListSubscriber);
|
||||
// TaskList taskList = newTaskListSubscriber.getOnNextEvents().get(0);
|
||||
// assertEquals(7, taskList.tasks.size());
|
||||
// }*/
|
||||
//
|
||||
//}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.api;
|
||||
//
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.models.user.User;
|
||||
//import com.habitrpg.android.habitica.models.auth.UserAuthResponse;
|
||||
//
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.robolectric.RobolectricTestRunner;
|
||||
//import org.robolectric.annotation.Config;
|
||||
//
|
||||
//import android.os.Build;
|
||||
//
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//import rx.observers.TestSubscriber;
|
||||
//
|
||||
//import static junit.framework.Assert.assertEquals;
|
||||
//import static junit.framework.Assert.assertNotSame;
|
||||
//
|
||||
//@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.M)
|
||||
//@RunWith(RobolectricTestRunner.class)
|
||||
//public class UserAPITests extends BaseAPITests {
|
||||
//
|
||||
// /*@Test
|
||||
// public void shouldLoadUserFromServer() {
|
||||
// TestSubscriber<User> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.getUserData()
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// testSubscriber.assertValueCount(1);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldLoadCompleteUserFromServer() {
|
||||
// TestSubscriber<User> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.retrieveUser(true)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// testSubscriber.assertValueCount(1);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldRegisterNewUser() {
|
||||
// hostConfig.setUser("");
|
||||
// hostConfig.setApi("");
|
||||
// TestSubscriber<UserAuthResponse> testSubscriber = new TestSubscriber<>();
|
||||
// username = UUID.randomUUID().toString();
|
||||
// apiClient.registerUser(username, username+"@example.com", password, password)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// UserAuthResponse response = testSubscriber.getOnNextEvents().get(0);
|
||||
//
|
||||
// assertNotSame(hostConfig.getUserData(), response.getId());
|
||||
// assertNotSame(hostConfig.getApi(), response.getApiToken() != null ? response.getApiToken() : response.getToken());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldLoginExistingUser() {
|
||||
// TestSubscriber<UserAuthResponse> testSubscriber = new TestSubscriber<>();
|
||||
// apiClient.connectUser(username, password)
|
||||
// .subscribe(testSubscriber);
|
||||
// testSubscriber.awaitTerminalEvent();
|
||||
// testSubscriber.assertNoErrors();
|
||||
// testSubscriber.assertCompleted();
|
||||
// UserAuthResponse response = testSubscriber.getOnNextEvents().get(0);
|
||||
// assertEquals(hostConfig.getUserData(), response.getId());
|
||||
// assertEquals(hostConfig.getApi(), response.getApiToken() != null ? response.getApiToken() : response.getToken());
|
||||
// }*/
|
||||
//
|
||||
//}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.data.implementation;
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BaseTestCase;
|
||||
//import com.habitrpg.android.habitica.data.ApiClient;
|
||||
//import com.habitrpg.android.habitica.data.TaskRepository;
|
||||
//import com.habitrpg.android.habitica.data.local.UserLocalRepository;
|
||||
//import com.habitrpg.android.habitica.models.tasks.TaskList;
|
||||
//import com.habitrpg.android.habitica.models.tasks.TasksOrder;
|
||||
//import com.habitrpg.android.habitica.models.user.Flags;
|
||||
//import com.habitrpg.android.habitica.models.user.Items;
|
||||
//import com.habitrpg.android.habitica.models.user.Preferences;
|
||||
//import com.habitrpg.android.habitica.models.user.Stats;
|
||||
//import com.habitrpg.android.habitica.models.user.User;
|
||||
//
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import org.mockito.InjectMocks;
|
||||
//import org.mockito.Mock;
|
||||
//
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//import rx.Observable;
|
||||
//import rx.observers.TestSubscriber;
|
||||
//
|
||||
//import static junit.framework.Assert.assertEquals;
|
||||
//import static org.mockito.ArgumentMatchers.anyMap;
|
||||
//import static org.mockito.Mockito.never;
|
||||
//import static org.mockito.Mockito.verify;
|
||||
//import static org.mockito.Mockito.when;
|
||||
//
|
||||
//public class UserRepositoryImplTest extends BaseTestCase {
|
||||
//
|
||||
// @Mock
|
||||
// private ApiClient mockedApiClient;
|
||||
// @Mock
|
||||
// private UserLocalRepository mockedLocalRepository;
|
||||
// @Mock
|
||||
// private TaskRepository mockedTaskRepository;
|
||||
// @InjectMocks
|
||||
// private UserRepositoryImpl userRepository;
|
||||
// private User testUser;
|
||||
//
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() {
|
||||
// testUser = new User();
|
||||
// testUser.setId("123");
|
||||
// when(mockedLocalRepository.getUnmanagedCopy(testUser)).thenReturn(testUser);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdatingUserSavesChanges() {
|
||||
// testUser.setStats(new Stats());
|
||||
// User newUser = new User();
|
||||
// newUser.setItems(new Items());
|
||||
// newUser.setPreferences(new Preferences());
|
||||
// newUser.setFlags(new Flags());
|
||||
// newUser.setStats(new Stats());
|
||||
// TestSubscriber<User> subscriber = new TestSubscriber<>();
|
||||
// when(mockedApiClient.updateUser(anyMap())).thenReturn(Observable.just(newUser));
|
||||
// userRepository.updateUser(testUser, "preferences.timezoneOffset", 2).toBlocking().subscribe(subscriber);
|
||||
// Map<String, Object> updateData = new HashMap<>();
|
||||
// updateData.put("preferences.timezoneOffset", 2);
|
||||
// verify(mockedApiClient).updateUser(updateData);
|
||||
// verify(mockedLocalRepository).saveUser(testUser);
|
||||
// assertEquals(testUser.getEquipment(), newUser.getEquipment());
|
||||
// assertEquals(testUser.getPreferences(), newUser.getPreferences());
|
||||
// assertEquals(testUser.getFlags(), newUser.getFlags());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRetrievingUserSaves() {
|
||||
// when(mockedApiClient.retrieveUser(false)).thenReturn(Observable.just(testUser));
|
||||
// TestSubscriber<User> subscriber = new TestSubscriber<>();
|
||||
// userRepository.retrieveUser(false).toBlocking().subscribe(subscriber);
|
||||
// verify(mockedApiClient).retrieveUser(false);
|
||||
// verify(mockedLocalRepository).saveUser(testUser);
|
||||
// verify(mockedApiClient, never()).updateUser(anyMap());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRetrievingUserUpdatesTimezone() {
|
||||
// testUser.setPreferences(new Preferences());
|
||||
// testUser.getPreferences().setTimezoneOffset(99);
|
||||
// when(mockedApiClient.retrieveUser(false)).thenReturn(Observable.just(testUser));
|
||||
// TestSubscriber<User> subscriber = new TestSubscriber<>();
|
||||
// userRepository.retrieveUser(false).toBlocking().subscribe(subscriber);
|
||||
// verify(mockedApiClient).retrieveUser(false);
|
||||
// verify(mockedLocalRepository).saveUser(testUser);
|
||||
// verify(mockedApiClient).updateUser(anyMap());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRetrievingUserSavesTasks() {
|
||||
// testUser.setTasksOrder(new TasksOrder());
|
||||
// testUser.setTasks(new TaskList());
|
||||
// when(mockedApiClient.retrieveUser(false)).thenReturn(Observable.just(testUser));
|
||||
// TestSubscriber<User> subscriber = new TestSubscriber<>();
|
||||
// userRepository.retrieveUser(false).toBlocking().subscribe(subscriber);
|
||||
// subscriber.assertNoErrors();
|
||||
// verify(mockedApiClient).retrieveUser(false);
|
||||
// verify(mockedTaskRepository).saveTasks(testUser.getId(), testUser.getTasksOrder(), testUser.getTasks());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRetrievingUserDoesntRetrieveTwice() {
|
||||
// when(mockedApiClient.retrieveUser(false)).thenReturn(Observable.just(testUser));
|
||||
// TestSubscriber<User> subscriber = new TestSubscriber<>();
|
||||
// userRepository.retrieveUser(false).toBlocking().subscribe(subscriber);
|
||||
// userRepository.retrieveUser(false).toBlocking().subscribe(subscriber);
|
||||
// verify(mockedApiClient).retrieveUser(false);
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package com.habitrpg.android.habitica.helpers
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.util.*
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
class HealthFormatterTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NumberAbbreviatorTest {
|
||||
|
||||
private Context context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = mock(Context.class);
|
||||
|
||||
when(context.getString(R.string.thousand_abbrev)).thenReturn("k");
|
||||
when(context.getString(R.string.million_abbrev)).thenReturn("m");
|
||||
when(context.getString(R.string.billion_abbrev)).thenReturn("b");
|
||||
when(context.getString(R.string.trillion_abbrev)).thenReturn("t");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatItDoesntAbbreviatesSmallNumbers() {
|
||||
assertEquals("215", NumberAbbreviator.INSTANCE.abbreviate(context, 215, 2));
|
||||
assertEquals("2.05", NumberAbbreviator.INSTANCE.abbreviate(context, 2.05, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatItAbbreviatesThousand() {
|
||||
assertEquals("1.55k", NumberAbbreviator.INSTANCE.abbreviate(context, 1550, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatItAbbreviatesMillion() {
|
||||
assertEquals("9.99m", NumberAbbreviator.INSTANCE.abbreviate(context, 9990000, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatItAbbreviatesBillion() {
|
||||
assertEquals("1.99b", NumberAbbreviator.INSTANCE.abbreviate(context, 1990000000, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatItAbbreviatesThousandWithoutAdditionalDecimals() {
|
||||
assertEquals("1k", NumberAbbreviator.INSTANCE.abbreviate(context, 1000, 2));
|
||||
assertEquals("1.5k", NumberAbbreviator.INSTANCE.abbreviate(context, 1500, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voidtestThatitRoundsCorrectly() {
|
||||
assertEquals("9.99k", NumberAbbreviator.INSTANCE.abbreviate(context, 9999, 2));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.habitrpg.android.habitica.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.habitrpg.android.habitica.helpers.NumberAbbreviator.abbreviate
|
||||
import com.habitrpg.android.habitica.R
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class NumberAbbreviatorTest {
|
||||
@MockK private lateinit var context: Context
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
every { context.getString(R.string.thousand_abbrev) } returns "k"
|
||||
every { context.getString(R.string.million_abbrev) } returns "m"
|
||||
every { context.getString(R.string.billion_abbrev) } returns "b"
|
||||
every { context.getString(R.string.trillion_abbrev) } returns "t"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatItDoesntAbbreviatesSmallNumbers() {
|
||||
abbreviate(context, 215.0, 2) shouldBe "215"
|
||||
abbreviate(context, 2.05, 2) shouldBe "2.05"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatItAbbreviatesThousand() {
|
||||
abbreviate(context, 1550.0, 2) shouldBe "1.55k"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatItAbbreviatesMillion() {
|
||||
abbreviate(context, 9990000.0, 2) shouldBe "9.99m"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatItAbbreviatesBillion() {
|
||||
abbreviate(context, 1990000000.0, 2) shouldBe "1.99b"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatItAbbreviatesThousandWithoutAdditionalDecimals() {
|
||||
abbreviate(context, 1000.0, 2) shouldBe "1k"
|
||||
abbreviate(context, 1500.0, 2) shouldBe "1.5k"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun voidtestThatitRoundsCorrectly() {
|
||||
abbreviate(context, 9999.0, 2) shouldBe "9.99k"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.helpers;
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.api.HostConfig;
|
||||
//import com.habitrpg.android.habitica.models.Notification;
|
||||
//import com.habitrpg.android.habitica.models.notifications.LoginIncentiveData;
|
||||
//
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.mockito.Mockito;
|
||||
//import org.robolectric.RobolectricTestRunner;
|
||||
//import org.robolectric.RuntimeEnvironment;
|
||||
//import org.robolectric.annotation.Config;
|
||||
//import org.robolectric.shadows.ShadowAlertDialog;
|
||||
//
|
||||
//import android.app.AlertDialog;
|
||||
//import android.content.Context;
|
||||
//import android.os.Build;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.Assert.assertNull;
|
||||
//import static org.mockito.Mockito.mock;
|
||||
//import static org.mockito.Mockito.times;
|
||||
//import static org.mockito.Mockito.verify;
|
||||
//
|
||||
///**
|
||||
// * Created by krh12 on 12/9/2016.
|
||||
// */
|
||||
//
|
||||
//@Config(sdk = Build.VERSION_CODES.M)
|
||||
//public class PopupNotificationsManagerTest {
|
||||
//
|
||||
// public HostConfig hostConfig;
|
||||
// private Context context;
|
||||
// private NotificationsManager notificationsManager;
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() {
|
||||
// context = mock(Context.class);
|
||||
// hostConfig = new HostConfig(BuildConfig.BASE_URL,
|
||||
// BuildConfig.PORT,
|
||||
// "",
|
||||
// "");
|
||||
// notificationsManager = new NotificationsManager(context);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void itDoesNothingWhenNotificationsListIsEmpty() {
|
||||
// List<Notification> notifications = new ArrayList<>();
|
||||
// notificationsManager.handlePopupNotifications(notifications);
|
||||
//
|
||||
// AlertDialog alert =
|
||||
// ShadowAlertDialog.getLatestAlertDialog();
|
||||
// assertNull(alert);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// // @TODO: Eventually, we should have a list of implemented notifications and only use those
|
||||
// public void itShouldNotDisplayNotificationsThatAreNotLoginIncentives() {
|
||||
// List<Notification> notifications = new ArrayList<>();
|
||||
//
|
||||
// Notification notification = new Notification();
|
||||
// notification.setType("NOT_LOGIN_INCENTIVE");
|
||||
//
|
||||
// notifications.add(notification);
|
||||
//
|
||||
// final NotificationsManager testClass = mock(NotificationsManager.class);
|
||||
// Mockito.when(testClass.displayLoginIncentiveNotification(notification)).thenReturn(true);
|
||||
// Mockito.when(testClass.handlePopupNotifications(notifications)).thenCallRealMethod();
|
||||
//
|
||||
// testClass.handlePopupNotifications(notifications);
|
||||
//
|
||||
// verify(testClass, times(0)).displayLoginIncentiveNotification(notification);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void itShouldDisplayADialogueForANotification() {
|
||||
// String testTitle = "Test Title";
|
||||
//
|
||||
// List<Notification> notifications = new ArrayList<>();
|
||||
//
|
||||
// LoginIncentiveData notificationData = new LoginIncentiveData();
|
||||
// notificationData.setMessage(testTitle);
|
||||
//
|
||||
// Notification notification = new Notification();
|
||||
// notification.setType("LOGIN_INCENTIVE");
|
||||
// notification.setData(notificationData);
|
||||
//
|
||||
// notifications.add(notification);
|
||||
//
|
||||
// final NotificationsManager testClass = mock(NotificationsManager.class);
|
||||
// Mockito.when(testClass.displayLoginIncentiveNotification(notification)).thenReturn(true);
|
||||
// Mockito.when(testClass.handlePopupNotifications(notifications)).thenCallRealMethod();
|
||||
//
|
||||
// testClass.handlePopupNotifications(notifications);
|
||||
//
|
||||
// verify(testClass, times(1)).displayLoginIncentiveNotification(notification);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void itShouldNotDisplayANotificationTwice() {
|
||||
// String testTitle = "Test Title";
|
||||
//
|
||||
// List<Notification> notifications = new ArrayList<>();
|
||||
//
|
||||
// LoginIncentiveData notificationData = new LoginIncentiveData();
|
||||
// notificationData.setMessage(testTitle);
|
||||
//
|
||||
// Notification notification = new Notification();
|
||||
// notification.setType("LOGIN_INCENTIVE");
|
||||
// notification.setData(notificationData);
|
||||
//
|
||||
// notifications.add(notification);
|
||||
// notifications.add(notification);
|
||||
//
|
||||
// final NotificationsManager testClass = mock(NotificationsManager.class);
|
||||
// Mockito.when(testClass.displayLoginIncentiveNotification(notification)).thenReturn(true);
|
||||
// Mockito.when(testClass.handlePopupNotifications(notifications)).thenCallRealMethod();
|
||||
//
|
||||
// testClass.handlePopupNotifications(notifications);
|
||||
//
|
||||
// verify(testClass, times(1)).displayLoginIncentiveNotification(notification);
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 7/16/16.
|
||||
*/
|
||||
public class RemindersManagerTest {
|
||||
|
||||
@Test
|
||||
public void itCreatesRemindersItemFromDateString() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,353 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.helpers;
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BuildConfig;
|
||||
//import com.habitrpg.android.habitica.receivers.TaskReceiver;
|
||||
//import com.habitrpg.android.habitica.models.tasks.Days;
|
||||
//import com.habitrpg.android.habitica.models.tasks.RemindersItem;
|
||||
//import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
//
|
||||
//import org.junit.After;
|
||||
//import org.junit.Assert;
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.robolectric.RobolectricTestRunner;
|
||||
//import org.robolectric.RuntimeEnvironment;
|
||||
//import org.robolectric.annotation.Config;
|
||||
//import org.robolectric.shadows.ShadowApplication;
|
||||
//
|
||||
//import android.app.PendingIntent;
|
||||
//import android.content.Context;
|
||||
//import android.content.Intent;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Calendar;
|
||||
//import java.util.List;
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//import io.realm.RealmList;
|
||||
//
|
||||
///**
|
||||
// * Created by keithholliday on 7/16/16.
|
||||
// */
|
||||
//
|
||||
//@Config(constants = BuildConfig.class)
|
||||
//@RunWith(value = RobolectricTestRunner.class)
|
||||
//public class TaskAlarmManagerTest {
|
||||
// private TaskAlarmManager taskAlarmManager;
|
||||
//
|
||||
// private Context context;
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() {
|
||||
// context = RuntimeEnvironment.application;
|
||||
// taskAlarmManager = new TaskAlarmManager(context);
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void tearDown() {
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testItSchedulesAlarmsForTodosWithMultipleReminders() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_TODO);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// UUID randomUUID = UUID.randomUUID();
|
||||
// remindersItem1.setId(randomUUID.toString());
|
||||
//
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
//
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
//
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
//
|
||||
// int intentId = remindersItem1.getId().hashCode() & 0xfffffff;
|
||||
// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
// intent.setAction(remindersItem1.getId());
|
||||
// PendingIntent sender = PendingIntent.getBroadcast(context, intentId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUp = sender != null;
|
||||
//
|
||||
// Assert.assertNotNull(intentId);
|
||||
// Assert.assertEquals(true, alarmUp);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void itUpdatesScheduledAlarmsForTodosWithMultipleReminders() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_TODO);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// UUID randomUUID = UUID.randomUUID();
|
||||
// remindersItem1.setId(randomUUID.toString());
|
||||
//
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
//
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
//
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
//
|
||||
// int alarmId = remindersItem1.getId().hashCode() & 0xfffffff;
|
||||
// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
// intent.setAction(remindersItem1.getId());
|
||||
// PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUp = sender != null;
|
||||
//
|
||||
// Assert.assertNotNull(alarmId);
|
||||
// Assert.assertEquals(true, alarmUp);
|
||||
//
|
||||
//
|
||||
// reminders = new RealmList<>();
|
||||
// cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
// int newAlarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
// PendingIntent senderNew = PendingIntent.getBroadcast(context, newAlarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUpNew = senderNew != null;
|
||||
//
|
||||
// Assert.assertNotNull(newAlarmId);
|
||||
// Assert.assertEquals(alarmId, newAlarmId);
|
||||
// Assert.assertEquals(true, alarmUpNew);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// //@TODO: Pending
|
||||
// public void itRemovesAlarmsWhenRemindersAreRemovedFromTodo() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_TODO);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
//// taskAlarmManager.setAlarmsForTask(task);
|
||||
////
|
||||
//// Integer alarmId = reminders.get(0).getAlarmId();
|
||||
//// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
//// intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
//// PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
//// try{ Thread.sleep(5000); }catch(InterruptedException e){ }
|
||||
//// PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
//// boolean alarmUp = sender != null;
|
||||
//// System.out.println(sender);
|
||||
//// Assert.assertNotNull(alarmId);
|
||||
//// Assert.assertEquals(true, alarmUp);
|
||||
//
|
||||
//// remindersItem1.delete();
|
||||
////
|
||||
//// PendingIntent senderUpdated = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
//// boolean alarmDown = senderUpdated == null;
|
||||
////
|
||||
//// Assert.assertEquals(true, alarmDown);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// //@TODO: Pending
|
||||
// public void itRemovesAlarmsWhenTodoIsDeleted() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void itScheduledAlarmForTheNextAvailableDayForRegularDaily() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_DAILY);
|
||||
// task.setFrequency(Task.FREQUENCY_WEEKLY);
|
||||
//
|
||||
// Days taskRepeatDays = new Days();
|
||||
// taskRepeatDays.setM(true);
|
||||
// taskRepeatDays.setS(false);
|
||||
// taskRepeatDays.setSu(false);
|
||||
// task.setRepeat(taskRepeatDays);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// UUID randomUUID = UUID.randomUUID();
|
||||
// remindersItem1.setId(randomUUID.toString());
|
||||
//
|
||||
// //We try to set a reminder on Tuesday, but the manager will correct this to Monday
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.DAY_OF_WEEK, 3);
|
||||
// cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
//
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
//
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
//
|
||||
// int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
//
|
||||
// Calendar newReminderTime = Calendar.getInstance();
|
||||
// newReminderTime.setTime(reminders.get(0).getTime());
|
||||
//
|
||||
// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
// intent.setAction(remindersItem1.getId());
|
||||
// PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUp = sender != null;
|
||||
//
|
||||
// Assert.assertNotNull(alarmId);
|
||||
// Assert.assertEquals(true, alarmUp);
|
||||
// Assert.assertEquals(1, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// //This also tests for when the receiver tries to schedule the next daily available
|
||||
// public void itScheduledAlarmForTheNextAvailableDayForRegularDailyWhenUserTriesToSetAlarmForNow() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_DAILY);
|
||||
// task.setFrequency(Task.FREQUENCY_WEEKLY);
|
||||
//
|
||||
// Days taskRepeatDays = new Days();
|
||||
// taskRepeatDays.setM(true);
|
||||
// taskRepeatDays.setT(true);
|
||||
// taskRepeatDays.setW(true);
|
||||
// taskRepeatDays.setTh(true);
|
||||
// taskRepeatDays.setF(true);
|
||||
// taskRepeatDays.setS(false);
|
||||
// taskRepeatDays.setSu(false);
|
||||
// task.setRepeat(taskRepeatDays);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// UUID randomUUID = UUID.randomUUID();
|
||||
// remindersItem1.setId(randomUUID.toString());
|
||||
//
|
||||
// //We try to set a reminder for now, but by the manager will correct (because the seconds will be different)
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
//
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
//
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
//
|
||||
// int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
//
|
||||
// Calendar newReminderTime = Calendar.getInstance();
|
||||
// newReminderTime.setTime(reminders.get(0).getTime());
|
||||
//
|
||||
// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
// intent.setAction(remindersItem1.getId());
|
||||
// PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUp = sender != null;
|
||||
//
|
||||
// Assert.assertNotNull(alarmId);
|
||||
// Assert.assertEquals(true, alarmUp);
|
||||
// Assert.assertNotSame(cal.getTime(), newReminderTime);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void itScheduledAlarmForTheNextAvailableDayForEveryXDayDaily() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_DAILY);
|
||||
// task.setFrequency(Task.FREQUENCY_DAILY);
|
||||
//
|
||||
// int everyXDay = 2;
|
||||
// task.setEveryX(everyXDay);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// UUID randomUUID = UUID.randomUUID();
|
||||
// remindersItem1.setId(randomUUID.toString());
|
||||
//
|
||||
// //We try to set a reminder one day after the start date, but the manager will correct since the
|
||||
// // daily is every 2 days from above
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// int currentDayOfTheWeek = cal.get(Calendar.DAY_OF_WEEK);
|
||||
//
|
||||
// task.setStartDate(cal.getTime());
|
||||
//
|
||||
// cal.set(Calendar.DAY_OF_WEEK, currentDayOfTheWeek + 1);
|
||||
// cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));
|
||||
//
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
//
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
//
|
||||
// int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
//
|
||||
// Calendar newReminderTime = Calendar.getInstance();
|
||||
// newReminderTime.setTime(reminders.get(0).getTime());
|
||||
//
|
||||
// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
// intent.setAction(remindersItem1.getId());
|
||||
// PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUp = sender != null;
|
||||
//
|
||||
// Assert.assertNotNull(alarmId);
|
||||
// Assert.assertEquals(true, alarmUp);
|
||||
//
|
||||
// int expectedDay = (currentDayOfTheWeek + everyXDay) % 7;
|
||||
// if (expectedDay == 0) { expectedDay = 7;};
|
||||
//
|
||||
// Assert.assertEquals(expectedDay, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// //This also tests for when the receiver tries to schedule the next daily available
|
||||
// public void itScheduledAlarmForTheNextAvailableDayForEveryXDayDailyWhenUserTriesToSetAlarmForNow() {
|
||||
// Task task = new Task();
|
||||
// task.setType(Task.TYPE_DAILY);
|
||||
// task.setFrequency(Task.FREQUENCY_DAILY);
|
||||
//
|
||||
// int everyXDay = 2;
|
||||
// task.setEveryX(everyXDay);
|
||||
//
|
||||
// RealmList<RemindersItem> reminders = new RealmList<>();
|
||||
// RemindersItem remindersItem1 = new RemindersItem();
|
||||
// UUID randomUUID = UUID.randomUUID();
|
||||
// remindersItem1.setId(randomUUID.toString());
|
||||
//
|
||||
// //We try to set a reminder for now, but the manager will correct since the seconds will be off
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// int currentDayOfTheWeek = cal.get(Calendar.DAY_OF_WEEK);
|
||||
//
|
||||
// remindersItem1.setTime(cal.getTime());
|
||||
// reminders.add(remindersItem1);
|
||||
//
|
||||
// task.setReminders(reminders);
|
||||
//
|
||||
// taskAlarmManager.setAlarmsForTask(task);
|
||||
//
|
||||
// int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
//
|
||||
// Calendar newReminderTime = Calendar.getInstance();
|
||||
// newReminderTime.setTime(reminders.get(0).getTime());
|
||||
//
|
||||
// Intent intent = new Intent(context, TaskReceiver.class);
|
||||
// intent.setAction(remindersItem1.getId());
|
||||
// PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
// boolean alarmUp = sender != null;
|
||||
//
|
||||
// Assert.assertNotNull(alarmId);
|
||||
// Assert.assertEquals(true, alarmUp);
|
||||
//
|
||||
// int expectedDay = (currentDayOfTheWeek + everyXDay) % 7;
|
||||
// if (expectedDay == 0) { expectedDay = 7;};
|
||||
//
|
||||
// Assert.assertEquals(expectedDay, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment;
|
||||
import com.habitrpg.android.habitica.models.members.Member;
|
||||
import com.habitrpg.android.habitica.models.user.Stats;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class UserStatComputerTest {
|
||||
|
||||
private UserStatComputer userStatComputer;
|
||||
private Member user;
|
||||
private Equipment equipment;
|
||||
private List<Equipment> equipmentList;
|
||||
private String key;
|
||||
private String text;
|
||||
|
||||
private int str = 1;
|
||||
private int intStat = 2;
|
||||
private int per = 3;
|
||||
private int con = 4;
|
||||
|
||||
public UserStatComputerTest () {
|
||||
userStatComputer = new UserStatComputer();
|
||||
user = new Member();
|
||||
Stats stats = new Stats();
|
||||
user.setStats(stats);
|
||||
|
||||
key = "example-key";
|
||||
text = "example-text";
|
||||
|
||||
equipment = new Equipment();
|
||||
equipment.setKey(key);
|
||||
equipment.setText(text);
|
||||
equipment.setStr(str);
|
||||
equipment.set_int(intStat);
|
||||
equipment.setPer(per);
|
||||
equipment.setCon(con);
|
||||
|
||||
equipmentList = new ArrayList<>();
|
||||
equipmentList.add(equipment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCorrectEquipmentRow () {
|
||||
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(equipmentList, user);
|
||||
UserStatComputer.EquipmentRow equipmentRow = (UserStatComputer.EquipmentRow) statsRows.get(0);
|
||||
|
||||
Assert.assertEquals(key, equipmentRow.getGearKey());
|
||||
Assert.assertEquals(text, equipmentRow.getText());
|
||||
Assert.assertEquals("STR 1, INT 2, CON 4, PER 3", equipmentRow.getStats());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnClassBonusRowWhenClassMatches () {
|
||||
user.getStats().setHabitClass(Stats.ROGUE);
|
||||
equipment.setKlass(Stats.ROGUE);
|
||||
|
||||
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(equipmentList, user);
|
||||
UserStatComputer.AttributeRow attributeRow = (UserStatComputer.AttributeRow) statsRows.get(2);
|
||||
|
||||
Assert.assertEquals(R.string.profile_class_bonus, attributeRow.getLabelId());
|
||||
Assert.assertEquals(str * 0.5f, attributeRow.getStrVal());
|
||||
Assert.assertEquals(intStat * 0.0f, attributeRow.getIntVal());
|
||||
Assert.assertEquals(con * 0.0f, attributeRow.getConVal());
|
||||
Assert.assertEquals(per * 0.5f, attributeRow.getPerVal());
|
||||
Assert.assertFalse(attributeRow.getRoundDown());
|
||||
Assert.assertFalse(attributeRow.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ShouldReturnClassBonusRowWhenSpecialClassMatches () {
|
||||
user.getStats().setHabitClass(Stats.ROGUE);
|
||||
equipment.setKlass("");
|
||||
equipment.setSpecialClass(Stats.ROGUE);
|
||||
|
||||
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(equipmentList, user);
|
||||
UserStatComputer.AttributeRow attributeRow = (UserStatComputer.AttributeRow) statsRows.get(2);
|
||||
|
||||
Assert.assertEquals(R.string.profile_class_bonus, attributeRow.getLabelId());
|
||||
Assert.assertEquals(str * 0.5f, attributeRow.getStrVal());
|
||||
Assert.assertEquals(intStat * 0.0f, attributeRow.getIntVal());
|
||||
Assert.assertEquals(con * 0.0f, attributeRow.getConVal());
|
||||
Assert.assertEquals(per * 0.5f, attributeRow.getPerVal());
|
||||
Assert.assertFalse(attributeRow.getRoundDown());
|
||||
Assert.assertFalse(attributeRow.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotReturnClassBonusWhenClassDoesNotMatch () {
|
||||
user.getStats().setHabitClass(Stats.ROGUE);
|
||||
equipment.setKlass("");
|
||||
equipment.setSpecialClass("");
|
||||
|
||||
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(equipmentList, user);
|
||||
UserStatComputer.AttributeRow attributeRow = (UserStatComputer.AttributeRow) statsRows.get(2);
|
||||
|
||||
Assert.assertEquals(R.string.profile_class_bonus, attributeRow.getLabelId());
|
||||
Assert.assertEquals(str *0.0f, attributeRow.getStrVal());
|
||||
Assert.assertEquals(intStat * 0.0f, attributeRow.getIntVal());
|
||||
Assert.assertEquals(con * 0.0f, attributeRow.getConVal());
|
||||
Assert.assertEquals(per * 0.0f, attributeRow.getPerVal());
|
||||
Assert.assertFalse(attributeRow.getRoundDown());
|
||||
Assert.assertFalse(attributeRow.getSummary());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
package com.habitrpg.android.habitica.helpers
|
||||
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment
|
||||
import com.habitrpg.android.habitica.helpers.UserStatComputer.EquipmentRow
|
||||
import com.habitrpg.android.habitica.helpers.UserStatComputer.AttributeRow
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.models.members.Member
|
||||
import com.habitrpg.android.habitica.models.user.Stats
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.ArrayList
|
||||
|
||||
class UserStatComputerTest {
|
||||
private val userStatComputer: UserStatComputer = UserStatComputer()
|
||||
private val user: Member = Member()
|
||||
private val equipment: Equipment
|
||||
private val equipmentList: MutableList<Equipment>
|
||||
private val key: String
|
||||
private val text: String
|
||||
private val str = 1
|
||||
private val intStat = 2
|
||||
private val per = 3
|
||||
private val con = 4
|
||||
@Test
|
||||
fun shouldReturnCorrectEquipmentRow() {
|
||||
val statsRows = userStatComputer.computeClassBonus(equipmentList, user)
|
||||
val equipmentRow = statsRows[0] as EquipmentRow
|
||||
assertEquals(key, equipmentRow.gearKey)
|
||||
assertEquals(text, equipmentRow.text)
|
||||
assertEquals("STR 1, INT 2, CON 4, PER 3", equipmentRow.stats)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldReturnClassBonusRowWhenClassMatches() {
|
||||
user.stats!!.habitClass = Stats.ROGUE
|
||||
equipment.klass = Stats.ROGUE
|
||||
val statsRows = userStatComputer.computeClassBonus(equipmentList, user)
|
||||
val attributeRow = statsRows[2] as AttributeRow
|
||||
assertEquals(R.string.profile_class_bonus.toLong(), attributeRow.labelId.toLong())
|
||||
assertEquals((str * 0.5f).toDouble(), attributeRow.strVal.toDouble(), 0.01)
|
||||
assertEquals((intStat * 0.0f).toDouble(), attributeRow.intVal.toDouble(), 0.01)
|
||||
assertEquals((con * 0.0f).toDouble(), attributeRow.conVal.toDouble(), 0.01)
|
||||
assertEquals((per * 0.5f).toDouble(), attributeRow.perVal.toDouble(), 0.01)
|
||||
assertFalse(attributeRow.roundDown)
|
||||
assertFalse(attributeRow.summary)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ShouldReturnClassBonusRowWhenSpecialClassMatches() {
|
||||
user.stats!!.habitClass = Stats.ROGUE
|
||||
equipment.klass = ""
|
||||
equipment.specialClass = Stats.ROGUE
|
||||
val statsRows = userStatComputer.computeClassBonus(equipmentList, user)
|
||||
val attributeRow = statsRows[2] as AttributeRow
|
||||
assertEquals(R.string.profile_class_bonus.toLong(), attributeRow.labelId.toLong())
|
||||
assertEquals((str * 0.5f).toDouble(), attributeRow.strVal.toDouble(), 0.01)
|
||||
assertEquals((intStat * 0.0f).toDouble(), attributeRow.intVal.toDouble(), 0.01)
|
||||
assertEquals((con * 0.0f).toDouble(), attributeRow.conVal.toDouble(), 0.01)
|
||||
assertEquals((per * 0.5f).toDouble(), attributeRow.perVal.toDouble(), 0.01)
|
||||
assertFalse(attributeRow.roundDown)
|
||||
assertFalse(attributeRow.summary)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldNotReturnClassBonusWhenClassDoesNotMatch() {
|
||||
user.stats?.habitClass = Stats.ROGUE
|
||||
equipment.klass = ""
|
||||
equipment.specialClass = ""
|
||||
val statsRows = userStatComputer.computeClassBonus(equipmentList, user)
|
||||
val attributeRow = statsRows[2] as AttributeRow
|
||||
assertEquals(R.string.profile_class_bonus.toLong(), attributeRow.labelId.toLong())
|
||||
assertEquals((str * 0.0f).toDouble(), attributeRow.strVal.toDouble(), 0.01)
|
||||
assertEquals((intStat * 0.0f).toDouble(), attributeRow.intVal.toDouble(), 0.01)
|
||||
assertEquals((con * 0.0f).toDouble(), attributeRow.conVal.toDouble(), 0.01)
|
||||
assertEquals((per * 0.0f).toDouble(), attributeRow.perVal.toDouble())
|
||||
assertFalse(attributeRow.roundDown)
|
||||
assertFalse(attributeRow.summary)
|
||||
}
|
||||
|
||||
init {
|
||||
val stats = Stats()
|
||||
user.stats = stats
|
||||
key = "example-key"
|
||||
text = "example-text"
|
||||
equipment = Equipment()
|
||||
equipment.key = key
|
||||
equipment.text = text
|
||||
equipment.str = str
|
||||
equipment._int = intStat
|
||||
equipment.per = per
|
||||
equipment.con = con
|
||||
equipmentList = ArrayList()
|
||||
equipmentList.add(equipment)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package com.habitrpg.android.habitica.models;
|
||||
|
||||
import com.habitrpg.android.habitica.models.user.SubscriptionPlan;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SubscriptionPlanTest {
|
||||
private SubscriptionPlan plan;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.plan = new SubscriptionPlan();
|
||||
this.plan.setCustomerId("fake_customer_id");
|
||||
this.plan.planId = "test";
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void isInactiveForNoPlanId() throws Exception {
|
||||
// this.plan.planId = null;
|
||||
// assertFalse(this.plan.isActive());
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void isActiveForNoTerminationDate() throws Exception {
|
||||
assertTrue(this.plan.isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isActiveForLaterTerminationDate() throws Exception {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
this.plan.dateTerminated = calendar.getTime();
|
||||
assertTrue(this.plan.isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isInactiveForEarlierTerminationDate() throws Exception {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.DATE, -1);
|
||||
this.plan.dateTerminated = calendar.getTime();
|
||||
assertFalse(this.plan.isActive());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.habitrpg.android.habitica.models
|
||||
|
||||
import com.habitrpg.android.habitica.models.user.SubscriptionPlan
|
||||
import org.junit.Before
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.lang.Exception
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import kotlin.Throws
|
||||
|
||||
class SubscriptionPlanTest {
|
||||
private var plan: SubscriptionPlan? = null
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
plan = SubscriptionPlan()
|
||||
plan!!.customerId = "fake_customer_id"
|
||||
plan!!.planId = "test"
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val isActiveForNoTerminationDate: Unit
|
||||
get() {
|
||||
Assertions.assertTrue(plan!!.isActive)
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val isActiveForLaterTerminationDate: Unit
|
||||
get() {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.time = Date()
|
||||
calendar.add(Calendar.DATE, 1)
|
||||
plan!!.dateTerminated = calendar.time
|
||||
Assertions.assertTrue(plan!!.isActive)
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val isInactiveForEarlierTerminationDate: Unit
|
||||
get() {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.time = Date()
|
||||
calendar.add(Calendar.DATE, -1)
|
||||
plan!!.dateTerminated = calendar.time
|
||||
Assertions.assertFalse(plan!!.isActive)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package com.habitrpg.android.habitica.models;
|
||||
|
||||
import com.habitrpg.android.habitica.models.user.Items;
|
||||
import com.habitrpg.android.habitica.models.user.OwnedMount;
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet;
|
||||
import com.habitrpg.android.habitica.models.user.User;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import io.realm.RealmList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class UserTest {
|
||||
|
||||
private User user;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
user = new User();
|
||||
Items items = new Items();
|
||||
user.setItems(items);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPetsFoundCount_shouldReturnSumOfAllPetEntries() {
|
||||
RealmList<OwnedPet> pets = new RealmList<>();
|
||||
pets.add(new OwnedPet());
|
||||
pets.add(new OwnedPet());
|
||||
pets.add(new OwnedPet());
|
||||
pets.add(new OwnedPet());
|
||||
pets.add(new OwnedPet());
|
||||
|
||||
user.getItems().setPets(pets);
|
||||
assertEquals(5, user.getPetsFoundCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPetsFoundCount_onNoPetCollectionAvailable_shouldReturnZero() {
|
||||
assertEquals(0, user.getPetsFoundCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMountsTamedCount_shouldReturnSumOfAllMountEntries() {
|
||||
RealmList<OwnedMount> mounts = new RealmList<>();
|
||||
mounts.add(new OwnedMount());
|
||||
mounts.add(new OwnedMount());
|
||||
mounts.add(new OwnedMount());
|
||||
mounts.add(new OwnedMount());
|
||||
mounts.add(new OwnedMount());
|
||||
|
||||
user.getItems().setMounts(mounts);
|
||||
assertEquals(5, user.getMountsTamedCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMountsTamedCount_onNoMountCollectionAvailable_shouldReturnZero() {
|
||||
assertEquals(0, user.getMountsTamedCount());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.habitrpg.android.habitica.models
|
||||
|
||||
import com.habitrpg.android.habitica.models.user.Items
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import io.realm.RealmList
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.models.user.OwnedMount
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import org.junit.jupiter.api.Assertions
|
||||
|
||||
class UserTest {
|
||||
private var user: User? = null
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
user = User()
|
||||
val items = Items()
|
||||
user!!.items = items
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val petsFoundCount_shouldReturnSumOfAllPetEntries: Unit
|
||||
get() {
|
||||
val pets = RealmList<OwnedPet>()
|
||||
pets.add(OwnedPet())
|
||||
pets.add(OwnedPet())
|
||||
pets.add(OwnedPet())
|
||||
pets.add(OwnedPet())
|
||||
pets.add(OwnedPet())
|
||||
user!!.items!!.pets = pets
|
||||
Assertions.assertEquals(5, user!!.petsFoundCount)
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val petsFoundCount_onNoPetCollectionAvailable_shouldReturnZero: Unit
|
||||
get() {
|
||||
Assertions.assertEquals(0, user!!.petsFoundCount)
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val mountsTamedCount_shouldReturnSumOfAllMountEntries: Unit
|
||||
get() {
|
||||
val mounts = RealmList<OwnedMount>()
|
||||
mounts.add(OwnedMount())
|
||||
mounts.add(OwnedMount())
|
||||
mounts.add(OwnedMount())
|
||||
mounts.add(OwnedMount())
|
||||
mounts.add(OwnedMount())
|
||||
user!!.items!!.mounts = mounts
|
||||
Assertions.assertEquals(5, user!!.mountsTamedCount)
|
||||
}
|
||||
|
||||
@get:Test
|
||||
val mountsTamedCount_onNoMountCollectionAvailable_shouldReturnZero: Unit
|
||||
get() {
|
||||
Assertions.assertEquals(0, user!!.mountsTamedCount)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +1,27 @@
|
|||
package com.habitrpg.android.habitica.models.inventory
|
||||
|
||||
import android.content.Context
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.getTranslatedType
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
private const val FAKE_STANDARD = "Standard"
|
||||
private const val FAKE_PREMIUM = "premium"
|
||||
|
||||
class MountTest {
|
||||
@Mock
|
||||
private var mockContext: Context = mock(Context::class.java)
|
||||
@MockK private lateinit var mockContext: Context
|
||||
private var mount: Mount = Mount()
|
||||
|
||||
@Test
|
||||
fun testGetTranslatedStringReturnsStandard() {
|
||||
mount.type = "drop"
|
||||
`when`(mockContext.getString(R.string.standard)).thenReturn(FAKE_STANDARD)
|
||||
every { mockContext.getString(R.string.standard) } returns FAKE_STANDARD
|
||||
|
||||
val result = mount.getTranslatedType(mockContext)
|
||||
|
||||
assertThat(result).isEqualTo(FAKE_STANDARD)
|
||||
result shouldBe FAKE_STANDARD
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -32,7 +29,6 @@ class MountTest {
|
|||
mount.type = "premium"
|
||||
|
||||
val result = mount.getTranslatedType(null)
|
||||
|
||||
assertThat(result).isEqualTo(FAKE_PREMIUM)
|
||||
result shouldBe FAKE_PREMIUM
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
package com.habitrpg.android.habitica.models.inventory
|
||||
|
||||
import android.content.Context
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.getTranslatedType
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.verify
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
||||
private const val FAKE_STANDARD = "Standard"
|
||||
private const val FAKE_PREMIUM = "premium"
|
||||
|
||||
class PetTest {
|
||||
@Mock
|
||||
private var mockContext: Context = mock(Context::class.java)
|
||||
@MockK private lateinit var mockContext: Context
|
||||
private var pet: Pet = Pet()
|
||||
|
||||
@Test
|
||||
fun testGetTranslatedStringReturnsStandard() {
|
||||
pet.type = "drop"
|
||||
`when`(mockContext.getString(R.string.standard)).thenReturn(FAKE_STANDARD)
|
||||
every { mockContext.getString(R.string.standard) } returns FAKE_STANDARD
|
||||
|
||||
val result = pet.getTranslatedType(mockContext)
|
||||
|
||||
assertThat(result).isEqualTo(FAKE_STANDARD)
|
||||
result shouldBe FAKE_STANDARD
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -33,6 +33,6 @@ class PetTest {
|
|||
|
||||
val result = pet.getTranslatedType(null)
|
||||
|
||||
assertThat(result).isEqualTo(FAKE_PREMIUM)
|
||||
result shouldBe FAKE_PREMIUM
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
//package com.habitrpg.android.habitica.ui.views.yesterdailies;
|
||||
//
|
||||
//import android.app.Activity;
|
||||
//import android.content.Context;
|
||||
//
|
||||
//import com.habitrpg.android.habitica.BaseTestCase;
|
||||
//import com.habitrpg.android.habitica.data.TaskRepository;
|
||||
//import com.habitrpg.android.habitica.data.UserRepository;
|
||||
//import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
//import com.habitrpg.android.habitica.models.user.User;
|
||||
//
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.mockito.Answers;
|
||||
//import org.mockito.Mock;
|
||||
//import org.powermock.api.mockito.PowerMockito;
|
||||
//import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
//import org.powermock.modules.junit4.PowerMockRunner;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import io.realm.RealmResults;
|
||||
//import rx.Observable;
|
||||
//
|
||||
//import static org.mockito.ArgumentMatchers.any;
|
||||
//import static org.mockito.ArgumentMatchers.anyString;
|
||||
//import static org.mockito.ArgumentMatchers.eq;
|
||||
//import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
//import static org.mockito.Mockito.times;
|
||||
//import static org.mockito.Mockito.when;
|
||||
//import static org.powermock.api.mockito.PowerMockito.verifyNew;
|
||||
//import static org.powermock.api.mockito.PowerMockito.whenNew;
|
||||
//
|
||||
//@RunWith(PowerMockRunner.class)
|
||||
//@PrepareForTest(YesterdailyDialog.class)
|
||||
//public class YesterdailyDialogTests extends BaseTestCase {
|
||||
//
|
||||
// @Mock
|
||||
// Activity mockContext;
|
||||
// @Mock
|
||||
// UserRepository mockUserRepository;
|
||||
// @Mock
|
||||
// TaskRepository mockTaskRepository;
|
||||
// @Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
// RealmResults<Task> mockResultsTasks;
|
||||
// @Mock
|
||||
// List<Task> mockTasks;
|
||||
//
|
||||
// @Mock
|
||||
// YesterdailyDialog mockDialog;
|
||||
//
|
||||
// User testUser;
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() throws Exception {
|
||||
// testUser = new User();
|
||||
// testUser.setId("123");
|
||||
// testUser.setNeedsCron(true);
|
||||
// whenNew(YesterdailyDialog.class).withAnyArguments().thenReturn(mockDialog);
|
||||
// when(mockUserRepository.getUser(anyString())).thenReturn(Observable.just(testUser));
|
||||
// when(mockTaskRepository.getTasks(anyString(), anyString())).thenReturn(Observable.just(mockResultsTasks));
|
||||
// when(mockTaskRepository.getTaskCopies(any(RealmResults.class))).thenReturn(Observable.just(mockTasks));
|
||||
// when(mockResultsTasks.where().equalTo("isDue", true).equalTo("completed", false).equalTo("yesterDaily", true).findAll()).thenReturn(mockResultsTasks);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void showsDialogIfNeededAndTasks() throws Exception {
|
||||
// when(mockTasks.size()).thenReturn(1);
|
||||
// YesterdailyDialog.Companion.showDialogIfNeeded(mockContext, "", mockUserRepository, mockTaskRepository);
|
||||
// verifyNew(YesterdailyDialog.class).withArguments(any(Context.class), any(UserRepository.class), any(List.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void doesntShowDialogIfAlreadyShown() throws Exception {
|
||||
// when(mockTasks.size()).thenReturn(1);
|
||||
// YesterdailyDialog.Companion.setIsDisplaying(true);
|
||||
// YesterdailyDialog.Companion.showDialogIfNeeded(mockContext, "", mockUserRepository, mockTaskRepository);
|
||||
// verifyNew(YesterdailyDialog.class, times(0)).withArguments(any(Context.class), any(UserRepository.class), any(List.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void doesntShowDialogIfNoTasks() throws Exception {
|
||||
// when(mockTasks.size()).thenReturn(0);
|
||||
// YesterdailyDialog.Companion.setIsDisplaying(true);
|
||||
// YesterdailyDialog.Companion.showDialogIfNeeded(mockContext, "", mockUserRepository, mockTaskRepository);
|
||||
// verifyNew(YesterdailyDialog.class, times(0)).withArguments(any(Context.class), any(UserRepository.class), any(List.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void doesntShowDialogIfNotNeeded() throws Exception {
|
||||
// testUser.setNeedsCron(false);
|
||||
// when(mockTasks.size()).thenReturn(1);
|
||||
// YesterdailyDialog.Companion.setIsDisplaying(true);
|
||||
// YesterdailyDialog.Companion.showDialogIfNeeded(mockContext, "", mockUserRepository, mockTaskRepository);
|
||||
// verifyNew(YesterdailyDialog.class, times(0)).withArguments(any(Context.class), any(UserRepository.class), any(List.class));
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
//package rx.plugins;
|
||||
//
|
||||
//public class RxJavaTestPlugins extends RxJavaPlugins {
|
||||
// RxJavaTestPlugins() {
|
||||
// super();
|
||||
// }
|
||||
//
|
||||
// public static void resetPlugins(){
|
||||
// getInstance().reset();
|
||||
// }
|
||||
//}
|
||||
Loading…
Reference in a new issue