Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Refactor: extract String constants in @receiver tests
  • Loading branch information
WonderCsabo committed Mar 4, 2016
commit 50a27c50a99c9ab591e4b6a89487a779d5e27dc0
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
@EActivity
public class ActivityWithReceiver extends Activity {

public static final String ACTION_1 = "org.androidannotations.ACTION_1";
public static final String ACTION_2 = "org.androidannotations.ACTION_2";
public static final String CUSTOM_HTTP_ACTION = "CUSTOM_HTTP_ACTION";

public boolean localWifiChangeIntentReceived = false;
public boolean dataSchemeHttpIntentReceived = false;
public boolean wifiChangeIntentReceived = false;
Expand All @@ -47,22 +51,22 @@ protected void onLocalWifiStateChanged() {
localWifiChangeIntentReceived = true;
}

@Receiver(actions = "CUSTOM_HTTP_ACTION", dataSchemes = "http", registerAt = Receiver.RegisterAt.OnCreateOnDestroy)
@Receiver(actions = CUSTOM_HTTP_ACTION, dataSchemes = "http", registerAt = Receiver.RegisterAt.OnCreateOnDestroy)
protected void onDataSchemeHttp(Intent intent) {
dataSchemeHttpIntentReceived = true;
}

@Receiver(actions = { "org.androidannotations.ACTION_1", "org.androidannotations.ACTION_2" }, registerAt = Receiver.RegisterAt.OnCreateOnDestroy)
@Receiver(actions = { ACTION_1, ACTION_2 }, registerAt = Receiver.RegisterAt.OnCreateOnDestroy)
protected void onBroadcastWithTwoActions(Intent intent) {
String action = intent.getAction();
if (action.equals("org.androidannotations.ACTION_1")) {
if (action.equals(ACTION_1)) {
action1Fired = true;
} else if (action.equals("org.androidannotations.ACTION_2")) {
} else if (action.equals(ACTION_2)) {
action2Fired = true;
}
}

@Receiver(actions = "org.androidannotations.ACTION_1")
@Receiver(actions = ACTION_1)
protected void onBroadcastWithExtras(Intent originalIntent, @Receiver.Extra Intent extraIntent) {
this.originalIntent = originalIntent;
this.extraIntent = extraIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public void onLocalWifiStateChangedTest() {

@Test
public void onDataShemeHttpTest() {
Intent intentFtp = new Intent("CUSTOM_HTTP_ACTION");
Intent intentFtp = new Intent(ActivityWithReceiver.CUSTOM_HTTP_ACTION);
intentFtp.setData(Uri.parse("ftp://androidannotations.org"));
activity.sendBroadcast(intentFtp);

assertFalse(activity.dataSchemeHttpIntentReceived);

Intent intentHttp = new Intent("CUSTOM_HTTP_ACTION");
Intent intentHttp = new Intent(ActivityWithReceiver.CUSTOM_HTTP_ACTION);
intentHttp.setData(Uri.parse("http://androidannotations.org"));
activity.sendBroadcast(intentHttp);

Expand All @@ -77,8 +77,8 @@ public void onDataShemeHttpTest() {

@Test
public void onBroadcastWithTwoActionsTest() {
Intent intent1 = new Intent("org.androidannotations.ACTION_1");
Intent intent2 = new Intent("org.androidannotations.ACTION_2");
Intent intent1 = new Intent(ActivityWithReceiver.ACTION_1);
Intent intent2 = new Intent(ActivityWithReceiver.ACTION_2);

assertFalse(activity.action1Fired);
assertFalse(activity.action2Fired);
Expand All @@ -94,7 +94,7 @@ public void onBroadcastWithTwoActionsTest() {

@Test
public void onBroadcastWithExtrasTest() {
Intent intent = new Intent("org.androidannotations.ACTION_1");
Intent intent = new Intent(ActivityWithReceiver.ACTION_1);
Intent extraIntent = new Intent("someAction");
intent.putExtra("extraIntent", extraIntent);

Expand Down