StorageConstraintPlugin extends PluginBase implements ConstraintsInterface { public static long getAvailableInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSizeLong(); long blocksAvailable = stat.getAvailableBlocksLong(); int size = 1048576; return ((blocksAvailable * blockSize) / size); } StorageConstraintPlugin(); static StorageConstraintPlugin getPlugin(); @Override Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value); static long getAvailableInternalMemorySize();  }
@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); }