DetailedBolusInfo test & fix

This commit is contained in:
Milos Kozak 2018-03-26 13:25:53 +02:00
parent 482d4f4454
commit 5c5b8ee2f0
3 changed files with 35 additions and 15 deletions

View file

@ -24,6 +24,7 @@ ext {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter { url "https://jcenter.bintray.com/" }
}
def generateGitBuild = { ->
@ -210,6 +211,7 @@ dependencies {
compile "com.google.guava:guava:20.0"
compile "net.danlew:android.joda:2.9.9.1"
compile "uk.com.robust-it:cloning:1.9.9"
compile 'org.mozilla:rhino:1.7.7.2'

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.data;
import android.content.Context;
import com.rits.cloning.Cloner;
import org.json.JSONObject;
import java.util.Date;
@ -30,21 +32,8 @@ public class DetailedBolusInfo {
public long deliverAt = 0; // SMB should be delivered within 1 min from this time
public DetailedBolusInfo copy() {
DetailedBolusInfo copy = new DetailedBolusInfo();
copy.date = this.date;
copy.eventType = this.eventType;
copy.insulin = this.insulin;
copy.carbs = this.carbs;
copy.source = this.source;
copy.isValid = this.isValid;
copy.glucose = this.glucose;
copy.glucoseType = this.glucoseType;
copy.carbTime = this.carbTime;
copy.boluscalc = this.boluscalc;
copy.context = this.context;
copy.pumpId = this.pumpId;
copy.isSMB = this.isSMB;
return copy;
Cloner cloner = new Cloner();
return cloner.deepClone(this);
}
@Override

View file

@ -0,0 +1,29 @@
package info.nightscout.androidaps.data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* Created by mike on 26.03.2018.
*/
@RunWith(PowerMockRunner.class)
public class DetailedBolusInfoTest {
@Test
public void toStringShouldBeOverloaded() {
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
Assert.assertEquals(true, detailedBolusInfo.toString().contains("insulin"));
}
@Test
public void copyShouldCopyAllProperties() {
DetailedBolusInfo d1 = new DetailedBolusInfo();
d1.deliverAt = 123;
DetailedBolusInfo d2 = d1.copy();
Assert.assertEquals(true, EqualsBuilder.reflectionEquals(d2, d1));
}
}