Merge branch 'dev' of https://github.com/MilosKozak/AndroidAPS into dev
This commit is contained in:
commit
640c7b56f1
|
@ -100,8 +100,8 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
|
||||||
String hours = " " + MainApp.gs(R.string.hours) + " ";
|
String hours = " " + MainApp.gs(R.string.hours) + " ";
|
||||||
|
|
||||||
if (useShortText) {
|
if (useShortText) {
|
||||||
days = "d";
|
days = MainApp.gs(R.string.shortday);
|
||||||
hours = "h";
|
hours = MainApp.gs(R.string.shorthour);
|
||||||
}
|
}
|
||||||
|
|
||||||
return diff.get(TimeUnit.DAYS) + days + diff.get(TimeUnit.HOURS) + hours;
|
return diff.get(TimeUnit.DAYS) + days + diff.get(TimeUnit.HOURS) + hours;
|
||||||
|
|
|
@ -185,7 +185,7 @@ public class DateUtil {
|
||||||
long remainingTimeMinutes = timeInMillis / (1000 * 60);
|
long remainingTimeMinutes = timeInMillis / (1000 * 60);
|
||||||
long remainingTimeHours = remainingTimeMinutes / 60;
|
long remainingTimeHours = remainingTimeMinutes / 60;
|
||||||
remainingTimeMinutes = remainingTimeMinutes % 60;
|
remainingTimeMinutes = remainingTimeMinutes % 60;
|
||||||
return "(" + ((remainingTimeHours > 0) ? (remainingTimeHours + "h ") : "") + remainingTimeMinutes + "')";
|
return "(" + ((remainingTimeHours > 0) ? (remainingTimeHours + MainApp.gs(R.string.shorthour) + " ") : "") + remainingTimeMinutes + "')";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sinceString(long timestamp) {
|
public static String sinceString(long timestamp) {
|
||||||
|
|
|
@ -778,6 +778,7 @@
|
||||||
<string name="shortgramm">g</string>
|
<string name="shortgramm">g</string>
|
||||||
<string name="shortminute">m</string>
|
<string name="shortminute">m</string>
|
||||||
<string name="shorthour">h</string>
|
<string name="shorthour">h</string>
|
||||||
|
<string name="shortday">d</string>
|
||||||
<string name="none"><![CDATA[<none>]]></string>
|
<string name="none"><![CDATA[<none>]]></string>
|
||||||
<string name="shortkilojoul">kJ</string>
|
<string name="shortkilojoul">kJ</string>
|
||||||
<string name="shortenergy">En</string>
|
<string name="shortenergy">En</string>
|
||||||
|
|
|
@ -107,6 +107,8 @@ public class AAPSMocker {
|
||||||
when(MainApp.gs(R.string.configbuilder_insulin)).thenReturn("Insulin");
|
when(MainApp.gs(R.string.configbuilder_insulin)).thenReturn("Insulin");
|
||||||
when(MainApp.gs(R.string.bolusdelivering)).thenReturn("Delivering 0.0U");
|
when(MainApp.gs(R.string.bolusdelivering)).thenReturn("Delivering 0.0U");
|
||||||
when(MainApp.gs(R.string.profile_per_unit)).thenReturn("/U");
|
when(MainApp.gs(R.string.profile_per_unit)).thenReturn("/U");
|
||||||
|
when(MainApp.gs(R.string.shortday)).thenReturn("d");
|
||||||
|
when(MainApp.gs(R.string.shorthour)).thenReturn("h");
|
||||||
when(MainApp.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U");
|
when(MainApp.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U");
|
||||||
when(MainApp.gs(R.string.profile_ins_units_per_hour)).thenReturn("U/h");
|
when(MainApp.gs(R.string.profile_ins_units_per_hour)).thenReturn("U/h");
|
||||||
when(MainApp.gs(R.string.sms_wrongcode)).thenReturn("Wrong code. Command cancelled.");
|
when(MainApp.gs(R.string.sms_wrongcode)).thenReturn("Wrong code. Command cancelled.");
|
||||||
|
|
|
@ -3,6 +3,7 @@ apply plugin: 'com.android.application'
|
||||||
ext {
|
ext {
|
||||||
wearableVersion = "2.4.0"
|
wearableVersion = "2.4.0"
|
||||||
playServicesWearable = "17.0.0"
|
playServicesWearable = "17.0.0"
|
||||||
|
powermockVersion = "1.7.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateGitBuild = { ->
|
def generateGitBuild = { ->
|
||||||
|
@ -101,4 +102,18 @@ dependencies {
|
||||||
implementation 'androidx.wear:wear:1.0.0'
|
implementation 'androidx.wear:wear:1.0.0'
|
||||||
implementation('me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0')
|
implementation('me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0')
|
||||||
implementation('com.github.lecho:hellocharts-library:1.5.8@aar')
|
implementation('com.github.lecho:hellocharts-library:1.5.8@aar')
|
||||||
|
|
||||||
|
testImplementation "junit:junit:4.12"
|
||||||
|
testImplementation "org.json:json:20140107"
|
||||||
|
testImplementation "org.mockito:mockito-core:2.8.47"
|
||||||
|
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
|
||||||
|
testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}"
|
||||||
|
testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}"
|
||||||
|
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
|
||||||
|
testImplementation "joda-time:joda-time:2.9.9"
|
||||||
|
testImplementation("com.google.truth:truth:0.39") {
|
||||||
|
exclude group: "com.google.guava", module: "guava"
|
||||||
|
}
|
||||||
|
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
||||||
|
testImplementation "org.hamcrest:hamcrest-all:1.3"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
package info.nightscout.androidaps.interaction.utils;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by dlvoy on 21.11.2019.
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class SafeParseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringToDoubleTest() {
|
||||||
|
// correct values
|
||||||
|
assertThat(0.1234, is(SafeParse.stringToDouble("0.1234")));
|
||||||
|
assertThat(0.1234, is(SafeParse.stringToDouble("0,1234")));
|
||||||
|
assertThat(0.5436564812, is(SafeParse.stringToDouble(".5436564812")));
|
||||||
|
assertThat(0.5436564812, is(SafeParse.stringToDouble(",5436564812")));
|
||||||
|
assertThat(1000500100900.0, is(SafeParse.stringToDouble("1000500100900")));
|
||||||
|
assertThat(42.0, is(SafeParse.stringToDouble("42")));
|
||||||
|
|
||||||
|
// units or other extra values are not permitted
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("12 U/h")));
|
||||||
|
|
||||||
|
// strings are not parsable
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("ala ma kota")));
|
||||||
|
|
||||||
|
// separator errors
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("0.1234.5678")));
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("0,1234,5678")));
|
||||||
|
|
||||||
|
// various emptiness
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("")));
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble(" ")));
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("\n\r")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringToIntTest() {
|
||||||
|
// correct values
|
||||||
|
assertThat(1052934, is(SafeParse.stringToInt("1052934")));
|
||||||
|
assertThat(-42, is(SafeParse.stringToInt("-42")));
|
||||||
|
assertThat(2147483647, is(SafeParse.stringToInt("2147483647")));
|
||||||
|
assertThat(-2147483648, is(SafeParse.stringToInt("-2147483648")));
|
||||||
|
|
||||||
|
// outside Integer range
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("2147483648")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("-2147483649")));
|
||||||
|
|
||||||
|
// units or other extra values are not permitted
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("12 U/h")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("0.1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("0,1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt(".5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt(",5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("42.1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("42,1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("3212.5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("3212,5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("1000500100900")));
|
||||||
|
|
||||||
|
// strings are not parsable
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("ala ma kota")));
|
||||||
|
|
||||||
|
// various emptiness
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt(" ")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("\n\r")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringToLongTest() {
|
||||||
|
// correct values
|
||||||
|
assertThat(1052934L, is(SafeParse.stringToLong("1052934")));
|
||||||
|
assertThat(-42L, is(SafeParse.stringToLong("-42")));
|
||||||
|
assertThat(2147483647L, is(SafeParse.stringToLong("2147483647")));
|
||||||
|
assertThat(-2147483648L, is(SafeParse.stringToLong("-2147483648")));
|
||||||
|
assertThat(1000500100900L, is(SafeParse.stringToLong("1000500100900")));
|
||||||
|
|
||||||
|
// outside Integer range
|
||||||
|
assertThat(2147483648L, is(SafeParse.stringToLong("2147483648")));
|
||||||
|
assertThat(-2147483649L, is(SafeParse.stringToLong("-2147483649")));
|
||||||
|
|
||||||
|
// units or other extra values are not permitted
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("12 U/h")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("0.1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("0,1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong(".5436564812")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong(",5436564812")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("42.1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("42,1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("3212.5436564812")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("3212,5436564812")));
|
||||||
|
|
||||||
|
// strings are not parsable
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("ala ma kota")));
|
||||||
|
|
||||||
|
// various emptiness
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong(" ")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("\n\r")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void stringToDoubleNullTest() {
|
||||||
|
SafeParse.stringToDouble(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void stringToIntNullTest() {
|
||||||
|
SafeParse.stringToInt(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void stringToLongNullTest() {
|
||||||
|
SafeParse.stringToLong(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepareMock() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue