Created
August 19, 2023 14:53
-
-
Save ProArun/cb7326b5adf97586b28b0fe97f7c0759 to your computer and use it in GitHub Desktop.
instrumentation test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import androidx.test.core.app.ApplicationProvider | |
import com.google.gson.JsonSyntaxException | |
import org.junit.Assert.* | |
import org.junit.After | |
import org.junit.Before | |
import org.junit.Test | |
import java.io.FileNotFoundException | |
class QuoteManagerTest { | |
@Before | |
fun setUp() { | |
} | |
@After | |
fun tearDown() { | |
} | |
@Test(expected = FileNotFoundException::class) | |
fun populateQuoteFromAssets_InvalidFileName_expected_Exception() { | |
val quoteManager = QuoteManager() | |
val context = ApplicationProvider.getApplicationContext<Context>() | |
quoteManager.populateQuoteFromAssets(context,"") | |
} | |
@Test(expected = JsonSyntaxException::class) | |
fun testPopulateQuoteFromAssets_InvalidJSON_expected_Exception(){ | |
val quoteManager = QuoteManager() | |
val context = ApplicationProvider.getApplicationContext<Context>() | |
quoteManager.populateQuoteFromAssets(context,"malformed.json") | |
} | |
@Test | |
fun testPopulateQuoteFromAssets_ValidJSON_expected_Count(){ | |
val quoteManager = QuoteManager() | |
val context = ApplicationProvider.getApplicationContext<Context>() | |
quoteManager.populateQuoteFromAssets(context,"quotes.json") | |
assertEquals(4,quoteManager.quoteList.size) | |
} | |
@Test | |
fun testPreviousQuote_expected_CorrectQuote(){ | |
//Arrange | |
val quoteManager = QuoteManager() | |
quoteManager.populateQuotes( | |
arrayOf( | |
Quote( "This is first quote","1"), | |
Quote( "This is second quote","2"), | |
Quote( "This is third quote","3") | |
)) | |
//Act | |
val quote = quoteManager.getPreviousQuote() | |
//Assert | |
assertEquals("1",quote.author) | |
} | |
@Test | |
fun testNextQuote_expected_CorrectQuote(){ | |
//Arrange | |
val quoteManager = QuoteManager() | |
quoteManager.populateQuotes( | |
arrayOf( | |
Quote( "This is first quote","1"), | |
Quote( "This is second quote","2"), | |
Quote( "This is third quote","3") | |
)) | |
//Act | |
val quote = quoteManager.getNextQuote() | |
//Assert | |
assertEquals("2",quote.author) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment