ConstraintTest

This commit is contained in:
Milos Kozak 2019-03-21 21:29:09 +01:00
parent beb50bad44
commit 9e05ea8c8e

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.interfaces;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
@ -9,6 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker; import info.AAPSMocker;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
/** /**
@ -16,15 +18,11 @@ import info.nightscout.androidaps.utils.SP;
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class}) @PrepareForTest({MainApp.class, SP.class, L.class})
public class ConstraintTest { public class ConstraintTest {
@Test @Test
public void doTests() { public void doTests() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
Constraint<Boolean> b = new Constraint<>(true); Constraint<Boolean> b = new Constraint<>(true);
Assert.assertEquals(Boolean.TRUE, b.value()); Assert.assertEquals(Boolean.TRUE, b.value());
Assert.assertEquals("", b.getReasons()); Assert.assertEquals("", b.getReasons());
@ -56,5 +54,18 @@ public class ConstraintTest {
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons()); Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons());
Assert.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons()); Assert.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons());
Assert.assertEquals(10d, d.originalValue()); Assert.assertEquals(10d, d.originalValue());
d.setIfDifferent(7d, "Set 7d", this);
Assert.assertEquals(7d, d.value());
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getReasons());
Assert.assertEquals("ConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getMostLimitedReasons());
Assert.assertEquals(10d, d.originalValue());
}
@Before
public void prepareMock() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
} }
} }