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:
siddharth2010 2018-06-11 10:46:12 +05:30 committed by Isaac Hutt
parent 99772598aa
commit 5c92e20b06
2 changed files with 0 additions and 30 deletions

0
#help# Normal file
View File

View File

@ -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