Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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.alertdialog;

import com.dspot.declex.test.R;

import static com.dspot.declex.actions.Action.*;

import org.androidannotations.annotations.EBean;

import java.util.ArrayList;
import java.util.List;


@EBean
public class ModelBean {
public void showAlertWithMessageAndTitle() {
$AlertDialog().title("Testing").message("Declex Test Now").positiveButton("Yes");
}

public void showAlertUsingStringResources() {
$AlertDialog().title(R.string.title)
.message(R.string.message)
.positiveButton(R.string.yes)
.negativeButton(R.string.no)
.neutralButton(R.string.ask_later);
}

public void showAlertItemSelection() {
String[] countries = new String[]{"United State", "France", "England", "China", "Japan"};
$AlertDialog().title("Select Countries").items(countries);

if ($AlertDialog.ItemSelected) {
int $position = 0;
String country = countries[$position];
}
}

public void showAlertMultiChoice() {
String[] countries = new String[]{"United State", "France", "England", "China", "Japan"};
$AlertDialog().title("Select Countries").multiChoice(countries);

if($AlertDialog.MultiChoiceSelected) {
int $position = 0;
String country = countries[$position];
}
}

public void showAlertMultiChoiceBooleanChecked() {
List<String> countries = new ArrayList<>();
boolean[] checkedItems = new boolean[]{ true, false, false, true, false };

$AlertDialog().title("Select Countries").multiChoice(countries, checkedItems);

if($AlertDialog.MultiChoiceSelected) {
int $position = 0;
String country = countries.get($position);
}
}

public void showAlertActionsButtons(Runnable Positive, Runnable Negative) {
$AlertDialog().title("Testing")
.message("Declex Test Now")
.positiveButton("Yes")
.negativeButton("No");

if($AlertDialog.PositiveButtonPressed) {
if(Positive != null) Positive.run();
}

if($AlertDialog.NegativeButtonPressed) {
if(Negative != null) Negative.run();
}
}
}
5 changes: 5 additions & 0 deletions declex-test/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<resources>
<string name="app_name">DecleX Test</string>
<string name="title">Testing</string>
<string name="message">DecleX Test Now</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="ask_later">Ask Later</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.dspot.declex.test.dialog.alertdialog;

import com.dspot.declex.actions.AlertDialogActionHolder_;
import com.dspot.declex.actions.runnable.DialogClickRunnable;
import com.dspot.declex.test.R;

import org.junit.Before;
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.ArrayList;
import java.util.List;

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, AlertDialogActionHolder_.class})
public class TestAlertDialog {

@Rule
public PowerMockRule rule = new PowerMockRule();

@Before
public void setUp() throws Exception {

}

@Test
public void testAlertDialogAction() {
AlertDialogActionHolder_ actionAlertDialog = AlertDialogActionHolder_.getInstance_(RuntimeEnvironment.application);
actionAlertDialog.init();

assertNotNull(actionAlertDialog);
assertNotNull(actionAlertDialog.builder());
}

@Test
public void testAlertDialogActionProperties() {
AlertDialogActionHolder_ actionAlertDialog = AlertDialogActionHolder_.getInstance_(RuntimeEnvironment.application);
actionAlertDialog.init();

assertNotNull(actionAlertDialog.builder());
assertNotNull(actionAlertDialog.title("Testing"));
assertNotNull(actionAlertDialog.message("Declex Test Now"));
assertNotNull(actionAlertDialog.positiveButton("Yes"));
}

@Test
public void testAlertDialogActionResources() {
AlertDialogActionHolder_ actionAlertDialog = AlertDialogActionHolder_.getInstance_(RuntimeEnvironment.application);
actionAlertDialog.init();

assertNotNull(actionAlertDialog.builder());
assertNotNull(actionAlertDialog.title(R.string.title));
assertNotNull(actionAlertDialog.message(R.string.message));
assertNotNull(actionAlertDialog.positiveButton(R.string.yes));
}

@Test
public void testAlertDialogActionSelectItems() {
String[] countries = (new String[]{"United State", "France", "England", "China", "Japan"});

AlertDialogActionHolder_ actionAlertDialog = AlertDialogActionHolder_.getInstance_(RuntimeEnvironment.application);
actionAlertDialog.init();

assertNotNull(actionAlertDialog.builder());
assertNotNull(actionAlertDialog.title("Select Countries"));
assertNotNull(actionAlertDialog.items(countries));
}

@Test
public void testAlertDialogActionMultiChoice() {
List<String> countries = new ArrayList<>();
boolean[] checkedItems = (new boolean[]{true, false, false, true, false});

AlertDialogActionHolder_ actionAlertDialog = AlertDialogActionHolder_.getInstance_(RuntimeEnvironment.application);
actionAlertDialog.init();

assertNotNull(actionAlertDialog.builder());
assertNotNull(actionAlertDialog.multiChoice(countries, checkedItems));
}

@Test
public void testAlertDialogButtonsAction() {
DialogClickRunnable PositiveButtonPressed = new DialogClickRunnable() {
@java.lang.Override
public void run() {

}
};
DialogClickRunnable NegativeButtonPressed = new DialogClickRunnable() {
@java.lang.Override
public void run() {

}
};

AlertDialogActionHolder_ actionAlertDialog = AlertDialogActionHolder_.getInstance_(RuntimeEnvironment.application);
actionAlertDialog.init();
actionAlertDialog.title("Testing");
actionAlertDialog.message("Declex Test Now");
actionAlertDialog.positiveButton("Yes");
actionAlertDialog.negativeButton("No");
actionAlertDialog.build(PositiveButtonPressed, NegativeButtonPressed, null, null, null, null, null);
actionAlertDialog.execute();

assertNotNull(actionAlertDialog.builder());
assertNotNull(actionAlertDialog.dialog());
}
}