AndroidAPS/app/src/test/java/info/nightscout/androidaps/utils/MidnightTimeTest.java

70 lines
2.1 KiB
Java
Raw Normal View History

2019-03-05 23:12:35 +01:00
package info.nightscout.androidaps.utils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Calendar;
import java.util.Date;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by mike on 20.11.2017.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Calendar.class})
public class MidnightTimeTest {
@Test
public void calc() {
// We get real midnight
long now = DateUtil.now();
Assert.assertTrue(now >= MidnightTime.calc());
Calendar c = Calendar.getInstance();
c.setTimeInMillis(MidnightTime.calc());
Assert.assertEquals(c.get(Calendar.HOUR_OF_DAY), 0);
Assert.assertEquals(c.get(Calendar.MINUTE), 0);
Assert.assertEquals(c.get(Calendar.SECOND), 0);
Assert.assertEquals(c.get(Calendar.MILLISECOND), 0);
}
@Test
public void calc_time() {
// We get real midnight
long now = DateUtil.now();
long midnight = MidnightTime.calc(now);
Assert.assertTrue(now >= midnight);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(MidnightTime.calc(now));
Assert.assertEquals(c.get(Calendar.HOUR_OF_DAY), 0);
Assert.assertEquals(c.get(Calendar.MINUTE), 0);
Assert.assertEquals(c.get(Calendar.SECOND), 0);
Assert.assertEquals(c.get(Calendar.MILLISECOND), 0);
// Assure we get the same time from cache
Assert.assertEquals(midnight, MidnightTime.calc(now));
}
2019-04-13 21:49:15 +02:00
@Test
public void resetCache() {
long now = DateUtil.now();
MidnightTime.calc(now);
MidnightTime.resetCache();
Assert.assertEquals(0, MidnightTime.times.size());
}
2019-03-05 23:12:35 +01:00
@Test
public void log() {
long now = DateUtil.now();
MidnightTime.calc(now);
2019-03-05 23:29:55 +01:00
Assert.assertTrue(MidnightTime.log().startsWith("Hits:"));
2019-03-05 23:12:35 +01:00
}
}