mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
fix the bug with powermock code
the code was not working as the file was being instantiated inside another class. So I have to find another method to mock the file.exists method in here.
This commit is contained in:
parent
99772598aa
commit
5c92e20b06
@ -90,36 +90,6 @@ public class FileUtilsTest {
|
||||
|
||||
files = FileUtils.getAllZimParts(testBook);
|
||||
assertEquals("Nothing is returned in this case", 0, files.size());
|
||||
|
||||
// Filename ends with .zimXX and the files "filename.zimaa" to "filename.zimfp" exists
|
||||
PowerMockito.when(myFile.getPath()).thenReturn(fileName + ".zimcd");
|
||||
PowerMockito.when(myFile.exists()).thenReturn(true);
|
||||
|
||||
String newPath = myFile.getPath();
|
||||
|
||||
// This file will return true whenever the File.exists() method is called
|
||||
File fileExists = PowerMockito.mock(File.class);
|
||||
PowerMockito.when(fileExists.exists()).thenReturn(true);
|
||||
|
||||
// This file will return false whenever the File.exists() method is called
|
||||
File fileDoesNotExist = PowerMockito.mock(File.class);
|
||||
PowerMockito.when(fileDoesNotExist.exists()).thenReturn(false);
|
||||
|
||||
for(char firstChar = 'a'; firstChar <= 'f'; firstChar++) {
|
||||
for(char secondChar = 'a'; secondChar <= 'z'; secondChar++) {
|
||||
newPath = newPath.substring(0, newPath.length() - 2) + firstChar + secondChar;
|
||||
PowerMockito.whenNew(File.class).withParameterTypes(String.class).withArguments(newPath).thenReturn(fileExists);
|
||||
if(firstChar == 'f' && secondChar == 'p'){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
newPath = newPath.substring(0, newPath.length() - 2) + 'f' + 'q';
|
||||
PowerMockito.whenNew(File.class).withParameterTypes(String.class).withArguments(newPath).thenReturn(fileDoesNotExist);
|
||||
files = FileUtils.getAllZimParts(testBook);
|
||||
assertEquals("Only a single book is returned in case the file has extension .zim", 0, files.size());
|
||||
assertEquals("The filename retained as such", testBook.file.getPath(), files.get(0).getPath());
|
||||
|
||||
}
|
||||
}
|
||||
// TODO : test deleteZimFile and getLocalFilePathByUrl
|
Loading…
x
Reference in New Issue
Block a user