diff --git a/declex-test/app/src/main/java/com/dspot/declex/test/dialog/progressdialog/ModelBean.java b/declex-test/app/src/main/java/com/dspot/declex/test/dialog/progressdialog/ModelBean.java new file mode 100644 index 00000000..c039cb7d --- /dev/null +++ b/declex-test/app/src/main/java/com/dspot/declex/test/dialog/progressdialog/ModelBean.java @@ -0,0 +1,64 @@ +/** + * Copyright (C) 2016-2017 DSpot Sp. z o.o + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.dspot.declex.test.dialog.progressdialog; + +import android.app.Dialog; + +import com.dspot.declex.test.R; + +import static com.dspot.declex.actions.Action.*; + +import org.androidannotations.annotations.EBean; + +@EBean +public class ModelBean { + public void downloadUsers() { + Dialog dialog = $ProgressDialog() + .title("Testing") + .message("DecleX Test Now") + .dialog(); + dialog.dismiss(); + } + + public void downloadUsersUsingResources() { + Dialog dialog = $ProgressDialog() + .title(R.string.title) + .message(R.string.message) + .dialog(); + dialog.dismiss(); + } + + public void downloadUsersWithActions(Runnable dismissed, Runnable shown) { + Dialog dialog = $ProgressDialog() + .title("Testing") + .message("DecleX Test Now") + .dialog(); + + if($ProgressDialog.Shown) { + if(shown != null) shown.run(); + } + + if($ProgressDialog.Dismissed) { + if(dismissed != null) dismissed.run(); + } + + dialog.dismiss(); + } + + public void showInformation(String information) { + $ProgressDialog().message("Upload information: {information} to the server"); + } +} diff --git a/declex-test/app/src/main/res/values/strings.xml b/declex-test/app/src/main/res/values/strings.xml index 9fe24759..7a8626ce 100644 --- a/declex-test/app/src/main/res/values/strings.xml +++ b/declex-test/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ DecleX Test + Testing + DecleX Test Now diff --git a/declex-test/app/src/test/java/com/dspot/declex/test/dialog/progressdialog/TestProgressDialog.java b/declex-test/app/src/test/java/com/dspot/declex/test/dialog/progressdialog/TestProgressDialog.java new file mode 100644 index 00000000..fc74307a --- /dev/null +++ b/declex-test/app/src/test/java/com/dspot/declex/test/dialog/progressdialog/TestProgressDialog.java @@ -0,0 +1,86 @@ +package com.dspot.declex.test.dialog.progressdialog; + +import com.dspot.declex.actions.ProgressDialogActionHolder_; +import com.dspot.declex.test.R; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.*; + +@RunWith(RobolectricTestRunner.class) +@Config( + manifest = "app/src/main/AndroidManifest.xml", + sdk = 25 +) +@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*", "org.powermock.*"}) +@PrepareForTest({ModelBean_.class, ProgressDialogActionHolder_.class}) +public class TestProgressDialog { + @Rule + public PowerMockRule rule = new PowerMockRule(); + + @Test + public void testProgressDialogAction() { + ProgressDialogActionHolder_ actionProgress = ProgressDialogActionHolder_.getInstance_(RuntimeEnvironment.application); + actionProgress.init(); + assertNotNull(actionProgress); + assertNotNull(actionProgress.dialog()); + } + + @Test + public void testProgressDialogActionProperties() { + ProgressDialogActionHolder_ actionProgress = ProgressDialogActionHolder_.getInstance_(RuntimeEnvironment.application); + actionProgress.init(); + assertNotNull(actionProgress); + assertNotNull(actionProgress.title("Testing")); + assertNotNull(actionProgress.message("DecleX Test Now")); + } + + @Test + public void testProgressDialogActionResources() { + ProgressDialogActionHolder_ actionProgress = ProgressDialogActionHolder_.getInstance_(RuntimeEnvironment.application); + actionProgress.init(); + assertNotNull(actionProgress); + assertNotNull(actionProgress.title(R.string.title)); + assertNotNull(actionProgress.message(R.string.message)); + + String information = "Data User Thomas"; + assertNotNull(actionProgress.message(((("Upload information: " + ((information) + "")) + " to the server")))); + } + + @Test + public void testProgressDialogActionEvents() { + Runnable shownAction = new Runnable() { + @Override + public void run() { + + } + }; + + Runnable dismissedAction = new Runnable() { + @Override + public void run() { + + } + }; + + ProgressDialogActionHolder_ actionProgress = ProgressDialogActionHolder_.getInstance_(RuntimeEnvironment.application); + actionProgress.init(); + actionProgress.build(shownAction, null, dismissedAction); + actionProgress.execute(); + + assertNotNull(actionProgress); + assertNotNull(actionProgress.dialog()); + assertNotNull(actionProgress.title("Testing")); + assertNotNull(actionProgress.message("DecleX Test Now")); + } +} \ No newline at end of file