Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
Fixed blank message issue and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatsushita committed Mar 14, 2014
1 parent 3079a33 commit 82f4d2a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/apb/beacon/model/SMSSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ public SMSSettings(List<String> phoneNumbers, String message) {
this.message = message;
}

public static void save(Context context, SMSSettings smsSettings) {
public static void saveContacts(Context context, SMSSettings smsSettings) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = settings.edit();
int i = 0;
for (String phoneNumber : smsSettings.phoneNumbers) {
String validPhoneDigit = phoneNumber.replaceAll("[- ]", "");
editor.putString(PHONE_NUMBER + i++, validPhoneDigit);
}
editor.putString(SMS_MESSAGE, smsSettings.message);
editor.commit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onClick(View v) {
Log.e(">>>>", "action button pressed");
SMSSettings newSMSSettings = getSMSSettingsFromView();

SMSSettings.save(activity, newSMSSettings);
SMSSettings.saveContacts(activity, newSMSSettings);
displaySettings(newSMSSettings);

String pageId = currentPage.getAction().get(0).getLink();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/apb/beacon/alert/PanicMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void setUp() {
finerLocation = LocationTestUtil.location(LocationManager.NETWORK_PROVIDER, finerLatitude, finerLongitude, currentTimeMillis(), 10.0f);

SMSSettings smsSettings = new SMSSettings(asList(mobile1, mobile2, mobile3), message);
SMSSettings.save(context, smsSettings);
SMSSettings.saveContacts(context, smsSettings);
SMSSettings.saveMessage(context, message);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ public void shouldReturnLocationWhichHasAlmostSameAccuracyAndRelativelyNew() {
public void shouldReturnLocationFromSameProviderAndNotSignificantlyAccurateButRelativelyNew() {
Location oldLocation = location(NETWORK_PROVIDER, 12.0, 20.0, currentTimeMillis(), LESS_ACCURATE);
Location lessAccurateButNewLocation = location(NETWORK_PROVIDER, 12.0, 20.0, offsetCurrentTimeBy(10), VERY_LESS_ACCURATE);
Location diffProviderLocation = location(GPS_PROVIDER, 12.0, 20.0, offsetCurrentTimeBy(20), VERY_LESS_ACCURATE + 10.0f);
Location diffMoreAccurateProviderLocation = location(GPS_PROVIDER, 12.0, 20.0, offsetCurrentTimeBy(20), VERY_LESS_ACCURATE + 10.0f);
Location significantlyLessAccurateLocation = location(NETWORK_PROVIDER, 13.0, 20.0, offsetCurrentTimeBy(10), SIGNIFICANTLY_LESS_ACCURATE);

locationUpdateReceiver.onReceive(context, getIntent(oldLocation));
locationUpdateReceiver.onReceive(context, getIntent(lessAccurateButNewLocation));
locationUpdateReceiver.onReceive(context, getIntent(diffProviderLocation));
locationUpdateReceiver.onReceive(context, getIntent(diffMoreAccurateProviderLocation));
locationUpdateReceiver.onReceive(context, getIntent(significantlyLessAccurateLocation));

assertLocation(lessAccurateButNewLocation);
assertLocation(diffMoreAccurateProviderLocation);
}

private Intent getIntent(Location location) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/apb/beacon/model/SMSSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void shouldSaveAndRetrieveSMSSettings() throws Exception {

SMSSettings smsSettings = new SMSSettings(expectedPhoneNumbers, expectedMessage);

SMSSettings.save(context, smsSettings);
SMSSettings.saveContacts(context, smsSettings);
SMSSettings.saveMessage(context, expectedMessage);
SMSSettings retrievedSMSSettings = SMSSettings.retrieve(context);

assertEquals(expectedMessage, retrievedSMSSettings.message());
Expand Down

0 comments on commit 82f4d2a

Please sign in to comment.