From 819bd775233853c551f71518934f7c067f720ce1 Mon Sep 17 00:00:00 2001 From: siddharth2010 Date: Wed, 13 Jun 2018 17:28:06 +0530 Subject: [PATCH] test for getAllZimParts complete. need to fix a small bug --- .../files/FileUtilsInstrumentationTest.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/androidTestKiwix/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.java b/app/src/androidTestKiwix/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.java index 5889e39dd..1f1924bf3 100644 --- a/app/src/androidTestKiwix/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.java +++ b/app/src/androidTestKiwix/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.java @@ -5,10 +5,9 @@ import android.support.test.InstrumentationRegistry; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.Random; import org.junit.Before; 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.mockito.MockitoAnnotations; @@ -17,20 +16,12 @@ import static org.junit.Assert.assertEquals; public class FileUtilsInstrumentationTest { private Context context; - private boolean mockInitialized = false; private File testDir; @Before public void executeBefore() { - if (!mockInitialized) { - MockitoAnnotations.initMocks(this); - mockInitialized = true; - } context = InstrumentationRegistry.getTargetContext(); testDir = context.getDir("testDir", context.MODE_PRIVATE); - - //File newTestFile2 = new File(newTestFile.getPath()); - //assertEquals("assert file exists", true, newTestFile2.exists()); } @Test @@ -50,21 +41,29 @@ public class FileUtilsInstrumentationTest { // Filename ends with .zimXX and the files up till "FileName.zimer" exist // i.e. 26 * 4 + 18 = 122 files exist String fileName = "/" + testId + "testfile.zim"; + String fileNameWithExtension; + Random r = new Random(); + boolean bool[] = new boolean[122]; // Creating the files for the test + int index = 0; for (char char1 = 'a'; char1 <= 'z'; char1++) { 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(); if(char1 == 'e' && char2 == 'r') { break; } + index++; } if(char1 == 'e') { break; } } - + assertEquals("siddhartj", 121, index); // Test begins here Book book = new Book(); book.file = new File(testDir.getPath() + fileName + "bg"); @@ -74,6 +73,13 @@ public class FileUtilsInstrumentationTest { // Checking all the values returned 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