Merge branch 'dev' into smsrefactor
This commit is contained in:
commit
f25b629fbc
|
@ -104,7 +104,6 @@ public class AAPSMocker {
|
||||||
when(MainApp.gs(R.string.profile_per_unit)).thenReturn("/U");
|
when(MainApp.gs(R.string.profile_per_unit)).thenReturn("/U");
|
||||||
when(MainApp.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U");
|
when(MainApp.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U");
|
||||||
when(MainApp.gs(R.string.profile_ins_units_per_hout)).thenReturn("U/h");
|
when(MainApp.gs(R.string.profile_ins_units_per_hout)).thenReturn("U/h");
|
||||||
when(MainApp.gs(R.string.diskfull)).thenReturn("Free at least 200Mb from internal storage! Loop disabled!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainApp mockMainApp() {
|
public static MainApp mockMainApp() {
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.constraints.storage;
|
package info.nightscout.androidaps.plugins.constraints.storage;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.StatFs;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -8,6 +11,8 @@ import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -15,16 +20,21 @@ import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.powermock.api.mockito.PowerMockito.whenNew;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Rumen on 06.03.2019.
|
* Created by Rumen on 06.03.2019.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({MainApp.class, StorageConstraintPlugin.class})
|
@PrepareForTest({MainApp.class, StorageConstraintPlugin.class, StatFs.class, Environment.class})
|
||||||
public class StorageConstraintPluginTest extends StorageConstraintPlugin{
|
public class StorageConstraintPluginTest extends StorageConstraintPlugin{
|
||||||
|
|
||||||
StorageConstraintPlugin storageConstraintPlugin;
|
StorageConstraintPlugin storageConstraintPlugin;
|
||||||
|
private File mockedFile;
|
||||||
|
private static final String path = "/data";
|
||||||
|
private StatFs mockedStatFs;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isLoopInvocationAllowedTest(){
|
public void isLoopInvocationAllowedTest(){
|
||||||
|
@ -33,21 +43,38 @@ public class StorageConstraintPluginTest extends StorageConstraintPlugin{
|
||||||
when(StorageConstraintPlugin.getAvailableInternalMemorySize()).thenReturn(150L);
|
when(StorageConstraintPlugin.getAvailableInternalMemorySize()).thenReturn(150L);
|
||||||
Constraint<Boolean> c = new Constraint<>(true);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = storageConstraintPlugin.isClosedLoopAllowed(c);
|
c = storageConstraintPlugin.isClosedLoopAllowed(c);
|
||||||
Assert.assertEquals(true, c.getReasons().contains(MainApp.gs(R.string.diskfull)));
|
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
// Set free space over 200(Mb) to enable loop
|
// Set free space over 200(Mb) to enable loop
|
||||||
when(StorageConstraintPlugin.getAvailableInternalMemorySize()).thenReturn(300L);
|
when(StorageConstraintPlugin.getAvailableInternalMemorySize()).thenReturn(300L);
|
||||||
Constraint<Boolean> c2 = new Constraint<>(true);
|
Constraint<Boolean> c2 = new Constraint<>(true);
|
||||||
c2 = storageConstraintPlugin.isClosedLoopAllowed(c2);
|
c2 = storageConstraintPlugin.isClosedLoopAllowed(c2);
|
||||||
Assert.assertEquals(false, c2.getReasons().contains(MainApp.gs(R.string.diskfull)));
|
|
||||||
Assert.assertEquals(Boolean.TRUE, c2.value());
|
Assert.assertEquals(Boolean.TRUE, c2.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailableInternalMemorySizeTest() throws Exception {
|
||||||
|
PowerMockito.mockStatic(Environment.class);
|
||||||
|
PowerMockito.when(Environment.getDataDirectory()).thenReturn(mockedFile);
|
||||||
|
when(mockedFile.getPath()).thenReturn(path);
|
||||||
|
when(mockedFile.exists()).thenReturn(true);
|
||||||
|
|
||||||
|
whenNew(StatFs.class).withArguments(any()).thenReturn(mockedStatFs);
|
||||||
|
when(mockedStatFs.getBlockSizeLong()).thenReturn(1024L);
|
||||||
|
when(mockedStatFs.getAvailableBlocksLong()).thenReturn(150l*1024);
|
||||||
|
|
||||||
|
long freeSpaceInMb = storageConstraintPlugin.getAvailableInternalMemorySize();
|
||||||
|
Assert.assertEquals(150L, freeSpaceInMb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareMock() {
|
public void prepareMock() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockStrings();
|
AAPSMocker.mockStrings();
|
||||||
// PowerMockito.mockStatic(Environment.class);
|
AAPSMocker.mockBus();
|
||||||
|
mockedFile = mock(File.class);
|
||||||
|
mockedStatFs = mock(StatFs.class);
|
||||||
storageConstraintPlugin = StorageConstraintPlugin.getPlugin();
|
storageConstraintPlugin = StorageConstraintPlugin.getPlugin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue