mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
test for getAllZimParts complete. need to fix a small bug
This commit is contained in:
parent
08bca7507b
commit
819bd77523
@ -5,10 +5,9 @@ import android.support.test.InstrumentationRegistry;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kiwix.kiwixmobile.data.local.KiwixDatabase;
|
|
||||||
import org.kiwix.kiwixmobile.data.local.dao.BookDao;
|
|
||||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity.Book;
|
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity.Book;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@ -17,20 +16,12 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class FileUtilsInstrumentationTest {
|
public class FileUtilsInstrumentationTest {
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
private boolean mockInitialized = false;
|
|
||||||
private File testDir;
|
private File testDir;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void executeBefore() {
|
public void executeBefore() {
|
||||||
if (!mockInitialized) {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mockInitialized = true;
|
|
||||||
}
|
|
||||||
context = InstrumentationRegistry.getTargetContext();
|
context = InstrumentationRegistry.getTargetContext();
|
||||||
testDir = context.getDir("testDir", context.MODE_PRIVATE);
|
testDir = context.getDir("testDir", context.MODE_PRIVATE);
|
||||||
|
|
||||||
//File newTestFile2 = new File(newTestFile.getPath());
|
|
||||||
//assertEquals("assert file exists", true, newTestFile2.exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -50,21 +41,29 @@ public class FileUtilsInstrumentationTest {
|
|||||||
// Filename ends with .zimXX and the files up till "FileName.zimer" exist
|
// Filename ends with .zimXX and the files up till "FileName.zimer" exist
|
||||||
// i.e. 26 * 4 + 18 = 122 files exist
|
// i.e. 26 * 4 + 18 = 122 files exist
|
||||||
String fileName = "/" + testId + "testfile.zim";
|
String fileName = "/" + testId + "testfile.zim";
|
||||||
|
String fileNameWithExtension;
|
||||||
|
Random r = new Random();
|
||||||
|
boolean bool[] = new boolean[122];
|
||||||
|
|
||||||
// Creating the files for the test
|
// Creating the files for the test
|
||||||
|
int index = 0;
|
||||||
for (char char1 = 'a'; char1 <= 'z'; char1++) {
|
for (char char1 = 'a'; char1 <= 'z'; char1++) {
|
||||||
for (char char2 = 'a'; char2 <= 'z'; char2++) {
|
for (char char2 = 'a'; char2 <= 'z'; char2++) {
|
||||||
File file = new File(testDir.getPath() + fileName + char1 + char2);
|
bool[index] = r.nextBoolean();
|
||||||
|
fileNameWithExtension = fileName + char1 + char2;
|
||||||
|
fileNameWithExtension = bool[index] ? fileNameWithExtension : fileNameWithExtension + ".part";
|
||||||
|
File file = new File(testDir.getPath() + fileNameWithExtension);
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
if(char1 == 'e' && char2 == 'r') {
|
if(char1 == 'e' && char2 == 'r') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
if(char1 == 'e') {
|
if(char1 == 'e') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assertEquals("siddhartj", 121, index);
|
||||||
// Test begins here
|
// Test begins here
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.file = new File(testDir.getPath() + fileName + "bg");
|
book.file = new File(testDir.getPath() + fileName + "bg");
|
||||||
@ -74,6 +73,13 @@ public class FileUtilsInstrumentationTest {
|
|||||||
// Checking all the values returned
|
// Checking all the values returned
|
||||||
assertEquals("26 * 4 + 18 = 122 files should be returned", 122, files.size());
|
assertEquals("26 * 4 + 18 = 122 files should be returned", 122, files.size());
|
||||||
|
|
||||||
|
for(index = 0; index < 122; index++ ) {
|
||||||
|
if(bool[index]) {
|
||||||
|
assertEquals("if the file fileName.zimXX exists, then no need to add the .part extension at the end", false, files.get(index).getPath().endsWith(".part"));
|
||||||
|
} else {
|
||||||
|
//assertEquals("if the file fileName.zimXX.part exists, then the file returned should also have the same ending .zimXX.part", true, files.get(index).getPath().endsWith(".part"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Deleting the Files
|
// Deleting the Files
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user