added test for getAvailableInternalMemorySize()
it took me some time, but it's OK now
This commit is contained in:
parent
f7c6f60131
commit
065192f11e
1 changed files with 30 additions and 2 deletions
|
@ -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(){
|
||||||
|
@ -43,11 +53,29 @@ public class StorageConstraintPluginTest extends StorageConstraintPlugin{
|
||||||
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);
|
mockedFile = mock(File.class);
|
||||||
|
mockedStatFs = mock(StatFs.class);
|
||||||
storageConstraintPlugin = StorageConstraintPlugin.getPlugin();
|
storageConstraintPlugin = StorageConstraintPlugin.getPlugin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue