AndroidAPS/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java

61 lines
2.5 KiB
Java
Raw Normal View History

package info.nightscout.androidaps.interfaces;
2018-03-19 13:11:25 +01:00
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
2018-07-30 20:23:48 +02:00
import org.powermock.core.classloader.annotations.PrepareForTest;
2018-03-19 13:11:25 +01:00
import org.powermock.modules.junit4.PowerMockRunner;
2018-07-30 20:23:48 +02:00
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
2019-02-26 20:38:27 +01:00
import info.nightscout.androidaps.utils.SP;
2018-07-30 20:23:48 +02:00
2018-03-19 13:11:25 +01:00
/**
* Created by mike on 19.03.2018.
*/
@RunWith(PowerMockRunner.class)
2018-07-30 20:23:48 +02:00
@PrepareForTest({MainApp.class, SP.class})
2018-03-19 17:38:48 +01:00
public class ConstraintTest {
2018-03-19 13:11:25 +01:00
@Test
2018-07-30 20:23:48 +02:00
public void doTests() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
2018-03-20 22:09:22 +01:00
Constraint<Boolean> b = new Constraint<>(true);
Assert.assertEquals(Boolean.TRUE, b.value());
Assert.assertEquals("", b.getReasons());
Assert.assertEquals("", b.getMostLimitedReasons());
2018-03-20 22:09:22 +01:00
b.set(false);
Assert.assertEquals(Boolean.FALSE, b.value());
Assert.assertEquals("", b.getReasons());
Assert.assertEquals("", b.getMostLimitedReasons());
b.set(true, "Set true", this);
2018-03-20 22:09:22 +01:00
Assert.assertEquals(Boolean.TRUE, b.value());
Assert.assertEquals("ConstraintTest: Set true", b.getReasons());
Assert.assertEquals("ConstraintTest: Set true", b.getMostLimitedReasons());
b.set(false, "Set false", this);
2018-03-20 22:09:22 +01:00
Assert.assertEquals(Boolean.FALSE, b.value());
Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons());
Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons());
2018-03-19 13:11:25 +01:00
2018-03-20 22:09:22 +01:00
Constraint<Double> d = new Constraint<>(10d);
d.set(5d, "Set 5d", this);
2018-03-20 23:47:37 +01:00
Assert.assertEquals(5d, d.value());
Assert.assertEquals("ConstraintTest: Set 5d", d.getReasons());
Assert.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons());
d.setIfSmaller(6d, "Set 6d", this);
2018-03-20 23:47:37 +01:00
Assert.assertEquals(5d, d.value());
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons());
Assert.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons());
d.setIfSmaller(4d, "Set 4d", this);
2018-03-20 23:47:37 +01:00
Assert.assertEquals(4d, d.value());
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons());
Assert.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons());
Assert.assertEquals(10d, d.originalValue());
2018-03-19 13:11:25 +01:00
}
}