This commit is contained in:
Markus M. May 2018-06-23 21:36:18 +02:00
parent de2273836e
commit e32f33a8d3
3 changed files with 46 additions and 1 deletions

View file

@ -1,5 +1,8 @@
package info.nightscout.androidaps.events;
import info.nightscout.utils.StringUtils;
public class EventNetworkChange extends Event {
public boolean mobileConnected = false;
@ -9,6 +12,6 @@ public class EventNetworkChange extends Event {
public boolean roaming = false;
public String getSsid() {
return ssid.replace("SSID: ","").replaceAll("\"","");
return StringUtils.removeSurroundingQuotes(ssid);
}
}

View file

@ -0,0 +1,20 @@
package info.nightscout.utils;
/**
* class contains useful String functions
*/
public class StringUtils {
private StringUtils() {
// this constructor is private, since this class should not get instantiated
}
public static String removeSurroundingQuotes(String string) {
if (string.length() >= 2 && string.charAt(0) == '"'
&& string.charAt(string.length() - 1) == '"') {
string = string.substring(1, string.length() - 1);
}
return string;
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.utils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class StringUtilsTest {
@Test
public void removeSurroundingQuotesTest() {
String compareString = "test";
assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString));
assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""));
assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString));
compareString = "te\"st";
assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString));
assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""));
assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString));
}
}