This commit is contained in:
parent
48aa7a887a
commit
0e370fee02
5 changed files with 37 additions and 57 deletions
|
@ -2,16 +2,11 @@ package info.nightscout.androidaps.testing.utils;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.data.BasalWatchData;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
public class BasalWatchDataExt extends BasalWatchData {
|
||||
|
||||
|
@ -22,16 +17,9 @@ public class BasalWatchDataExt extends BasalWatchData {
|
|||
public BasalWatchDataExt(BasalWatchData ref) {
|
||||
super();
|
||||
|
||||
Set<String> parentFields = new HashSet<>();
|
||||
for (Field f : BasalWatchData.class.getDeclaredFields()) {
|
||||
parentFields.add(f.getName());
|
||||
}
|
||||
|
||||
Set<String> knownFields = new HashSet<>(Arrays.asList("startTime,endTime,amount".split(",")));
|
||||
|
||||
// since we do not want modify BasalWatchData - we use this wrapper class
|
||||
// but we make sure it has same fields
|
||||
assertThat(parentFields, is(knownFields));
|
||||
assertClassHaveSameFields(BasalWatchData.class, "startTime,endTime,amount");
|
||||
|
||||
this.startTime = ref.startTime;
|
||||
this.endTime = ref.endTime;
|
||||
|
|
|
@ -2,16 +2,11 @@ package info.nightscout.androidaps.testing.utils;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.data.BgWatchData;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
public class BgWatchDataExt extends BgWatchData {
|
||||
|
||||
|
@ -26,16 +21,9 @@ public class BgWatchDataExt extends BgWatchData {
|
|||
public BgWatchDataExt(BgWatchData ref) {
|
||||
super();
|
||||
|
||||
Set<String> parentFields = new HashSet<>();
|
||||
for (Field f : BgWatchData.class.getDeclaredFields()) {
|
||||
parentFields.add(f.getName());
|
||||
}
|
||||
|
||||
Set<String> knownFields = new HashSet<>(Arrays.asList("sgv,high,low,timestamp,color".split(",")));
|
||||
|
||||
// since we do not want modify BgWatchDataExt - we use this wrapper class
|
||||
// but we make sure it has same fields
|
||||
assertThat(parentFields, is(knownFields));
|
||||
assertClassHaveSameFields(BgWatchData.class, "sgv,high,low,timestamp,color");
|
||||
|
||||
this.sgv = ref.sgv;
|
||||
this.high = ref.high;
|
||||
|
|
|
@ -2,16 +2,11 @@ package info.nightscout.androidaps.testing.utils;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.data.BolusWatchData;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
public class BolusWatchDataExt extends BolusWatchData {
|
||||
|
||||
|
@ -22,16 +17,9 @@ public class BolusWatchDataExt extends BolusWatchData {
|
|||
public BolusWatchDataExt(BolusWatchData ref) {
|
||||
super();
|
||||
|
||||
Set<String> parentFields = new HashSet<>();
|
||||
for (Field f : BolusWatchData.class.getDeclaredFields()) {
|
||||
parentFields.add(f.getName());
|
||||
}
|
||||
|
||||
Set<String> knownFields = new HashSet<>(Arrays.asList("date,bolus,carbs,isSMB,isValid".split(",")));
|
||||
|
||||
// since we do not want modify BolusWatchData - we use this wrapper class
|
||||
// but we make sure it has same fields
|
||||
assertThat(parentFields, is(knownFields));
|
||||
assertClassHaveSameFields(BolusWatchData.class, "date,bolus,carbs,isSMB,isValid");
|
||||
|
||||
this.date = ref.date;
|
||||
this.bolus = ref.bolus;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package info.nightscout.androidaps.testing.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
class ExtUtil {
|
||||
|
||||
static <T> void assertClassHaveSameFields(Class<T> checkedClass, String commaSeparatedFieldList) {
|
||||
Set<String> parentFields = new HashSet<>();
|
||||
for (Field f : checkedClass.getDeclaredFields()) {
|
||||
final String fieldName = f.getName();
|
||||
// skip runtime-injected fields like $jacocoData
|
||||
if (fieldName.startsWith("$")) {
|
||||
continue;
|
||||
}
|
||||
parentFields.add(fieldName);
|
||||
}
|
||||
|
||||
Set<String> knownFields = new HashSet<>(Arrays.asList(commaSeparatedFieldList.split(",")));
|
||||
assertThat(parentFields, is(knownFields));
|
||||
}
|
||||
|
||||
}
|
|
@ -2,16 +2,11 @@ package info.nightscout.androidaps.testing.utils;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.data.TempWatchData;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static info.nightscout.androidaps.testing.utils.ExtUtil.assertClassHaveSameFields;
|
||||
|
||||
|
||||
public class TempWatchDataExt extends TempWatchData {
|
||||
|
@ -23,16 +18,9 @@ public class TempWatchDataExt extends TempWatchData {
|
|||
public TempWatchDataExt(TempWatchData ref) {
|
||||
super();
|
||||
|
||||
Set<String> parentFields = new HashSet<>();
|
||||
for (Field f : TempWatchData.class.getDeclaredFields()) {
|
||||
parentFields.add(f.getName());
|
||||
}
|
||||
|
||||
Set<String> knownFields = new HashSet<>(Arrays.asList("startTime,startBasal,endTime,endBasal,amount".split(",")));
|
||||
|
||||
// since we do not want modify TempWatchData - we use this wrapper class
|
||||
// since we do not want modify BolusWatchData - we use this wrapper class
|
||||
// but we make sure it has same fields
|
||||
assertThat(parentFields, is(knownFields));
|
||||
assertClassHaveSameFields(TempWatchData.class, "startTime,startBasal,endTime,endBasal,amount");
|
||||
|
||||
this.startTime = ref.startTime;
|
||||
this.startBasal = ref.startBasal;
|
||||
|
|
Loading…
Reference in a new issue