From 293ef3063e5167adb0ed65f98efec09596b659bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jc=20Mi=C3=B1arro?= Date: Thu, 30 Jan 2020 22:12:27 +0100 Subject: [PATCH 1/5] Create Mother methods to obtain random Strings and Integers --- .../java/com/jcminarro/philology/Mother.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/philology/src/test/java/com/jcminarro/philology/Mother.kt b/philology/src/test/java/com/jcminarro/philology/Mother.kt index 0ce6236..6cea1eb 100644 --- a/philology/src/test/java/com/jcminarro/philology/Mother.kt +++ b/philology/src/test/java/com/jcminarro/philology/Mother.kt @@ -14,8 +14,22 @@ import org.amshove.kluent.When import org.amshove.kluent.calling import org.amshove.kluent.mock import java.util.Locale - -fun createConfiguration(locale: Locale = Locale.ENGLISH): Configuration = mock().apply { +import java.util.concurrent.ThreadLocalRandom + +private val charPool: List = ('a'..'z') + ('A'..'Z') + ('0'..'9') +private val random + get() = ThreadLocalRandom.current() + +fun randomBoolean() = random.nextBoolean() +fun randomInt() = random.nextInt() +fun randomFloat() = random.nextFloat() +fun randomString(size: Int = 20): String = (1..size) + .map { charPool[random.nextInt(0, charPool.size)] } + .joinToString(separator = "") +fun createConfiguration(locale: Locale = Locale.ENGLISH): Configuration = mock() + .configureLocale(locale) + +fun Configuration.configureLocale(locale: Locale) = this.apply { @Suppress("DEPRECATION") this.locale = locale When calling this.locales doReturn LocaleList(locale) From fefa825fe093ec477e7e4bb45fbabe7a14f6cb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jc=20Mi=C3=B1arro?= Date: Fri, 31 Jan 2020 21:39:19 +0100 Subject: [PATCH 2/5] Implement all "Resources method" on ResourcesUtil to use it as a proxy --- .../com/jcminarro/philology/ResourcesUtil.kt | 252 ++- .../jcminarro/philology/ResourcesUtilTest.kt | 1350 +++++++++++++++-- 2 files changed, 1425 insertions(+), 177 deletions(-) diff --git a/philology/src/main/java/com/jcminarro/philology/ResourcesUtil.kt b/philology/src/main/java/com/jcminarro/philology/ResourcesUtil.kt index 413e0a5..07c6dca 100644 --- a/philology/src/main/java/com/jcminarro/philology/ResourcesUtil.kt +++ b/philology/src/main/java/com/jcminarro/philology/ResourcesUtil.kt @@ -1,44 +1,239 @@ package com.jcminarro.philology +import android.annotation.SuppressLint +import android.annotation.TargetApi +import android.content.res.AssetFileDescriptor +import android.content.res.ColorStateList +import android.content.res.Configuration import android.content.res.Resources +import android.content.res.Resources.NotFoundException +import android.content.res.TypedArray +import android.content.res.XmlResourceParser +import android.graphics.Movie +import android.graphics.Typeface +import android.graphics.drawable.Drawable import android.icu.text.PluralRules import android.os.Build +import android.os.Bundle +import android.util.AttributeSet +import android.util.DisplayMetrics +import android.util.TypedValue +import androidx.annotation.AnimRes +import androidx.annotation.AnimatorRes +import androidx.annotation.AnyRes +import androidx.annotation.ArrayRes +import androidx.annotation.BoolRes +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.annotation.DimenRes +import androidx.annotation.DrawableRes +import androidx.annotation.FontRes +import androidx.annotation.FractionRes +import androidx.annotation.IntegerRes +import androidx.annotation.LayoutRes +import androidx.annotation.PluralsRes +import androidx.annotation.RawRes +import androidx.annotation.RequiresApi +import androidx.annotation.StringRes +import androidx.annotation.StyleableRes +import androidx.annotation.XmlRes +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException +import java.io.InputStream import java.util.Locale -internal class ResourcesUtil(private val baseResources: Resources) { +internal class ResourcesUtil(internal val baseResources: Resources) { + private val locale: Locale by lazy { baseResources.currentLocale() } private val repository: PhilologyRepository by lazy { - Philology.getPhilologyRepository(baseResources.currentLocale()) + Philology.getPhilologyRepository(locale) } - @Throws(Resources.NotFoundException::class) - fun getText(id: Int): CharSequence { - return repository.getText(baseResources.getResourceEntryName(id)) - ?: baseResources.getText(id) + @Throws(NotFoundException::class) + fun getText(@StringRes id: Int): CharSequence = getTextFromId(id) + + fun getText(@StringRes id: Int, def: CharSequence): CharSequence = try { + getTextFromId(id) + } catch (_: NotFoundException) { + def } - @Throws(Resources.NotFoundException::class) - fun getString(id: Int): String = getText(id).toString() + @Throws(NotFoundException::class) + fun getString(@StringRes id: Int): String = getTextFromId(id).toString() - @Throws(Resources.NotFoundException::class) - fun getQuantityText(id: Int, quantity: Int): CharSequence = repository.getPlural( - baseResources.getResourceEntryName(id), - quantity.toPluralKeyword(baseResources) - ) ?: baseResources.getQuantityText(id, quantity) + @Throws(NotFoundException::class) + fun getString(@StringRes id: Int, vararg formatArgs: Any?): String = + getFormattedText(getTextFromId(id).toString(), *formatArgs) + + @Throws(NotFoundException::class) + fun getQuantityText(@PluralsRes id: Int, quantity: Int): CharSequence = getQuantityTextFromId(id, quantity) + + @Throws(NotFoundException::class) + fun getQuantityString(@PluralsRes id: Int, quantity: Int): String = getQuantityTextFromId(id, quantity).toString() + + @Throws(NotFoundException::class) + fun getQuantityString(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any?): String = + getFormattedText(getQuantityTextFromId(id, quantity).toString(), *formatArgs) + + @Throws(NotFoundException::class) + fun getTextArray(@ArrayRes id: Int): Array = getTextArrayFromId(id) + + @Throws(NotFoundException::class) + fun getStringArray(@ArrayRes id: Int): Array = + getTextArrayFromId(id).map { it.toString() }.toTypedArray() - @Throws(Resources.NotFoundException::class) - fun getQuantityString(id: Int, quantity: Int): String = getQuantityText(id, quantity).toString() + @Throws(NotFoundException::class) + fun getAnimation(@AnimatorRes @AnimRes id: Int): XmlResourceParser = baseResources.getAnimation(id) - @Throws(Resources.NotFoundException::class) - fun getQuantityString(id: Int, quantity: Int, vararg formatArgs: Any?): String = - String.format(getQuantityString(id, quantity), *formatArgs) + fun getDisplayMetrics(): DisplayMetrics = baseResources.displayMetrics - fun getStringArray(id: Int): Array = - getTextArray(id).map { it.toString() }.toTypedArray() + @Throws(NotFoundException::class) + fun getDrawableForDensity(@DrawableRes id: Int, density: Int): Drawable? = + baseResources.getDrawableForDensity(id, density) - fun getTextArray(id: Int): Array { - return repository.getTextArray(baseResources.getResourceEntryName(id)) - ?: baseResources.getTextArray(id) + @Throws(NotFoundException::class) + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + fun getDrawableForDensity(@DrawableRes id: Int, density: Int, theme: Resources.Theme?): Drawable? = + baseResources.getDrawableForDensity(id, density, theme) + + fun getConfiguration(): Configuration = baseResources.configuration + + fun obtainAttributes(set: AttributeSet?, @StyleableRes attrs: IntArray?): TypedArray = + baseResources.obtainAttributes(set, attrs) + + @Throws(NotFoundException::class) + fun obtainTypedArray(@ArrayRes id: Int): TypedArray = baseResources.obtainTypedArray(id) + + @Throws(NotFoundException::class) + fun getDimensionPixelSize(@DimenRes id: Int): Int = baseResources.getDimensionPixelSize(id) + + @Throws(NotFoundException::class) + fun getIntArray(@ArrayRes id: Int): IntArray = baseResources.getIntArray(id) + + @Throws(NotFoundException::class) + fun getValue(@AnyRes id: Int, outValue: TypedValue?, resolveRefs: Boolean) { + baseResources.getValue(id, outValue, resolveRefs) } + + @Throws(NotFoundException::class) + fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean) { + baseResources.getValue(name, outValue, resolveRefs) + } + + @Throws(NotFoundException::class) + fun getResourcePackageName(@AnyRes resid: Int): String = + baseResources.getResourcePackageName(resid) + + @Throws(NotFoundException::class) + fun openRawResourceFd(@RawRes id: Int): AssetFileDescriptor = + baseResources.openRawResourceFd(id) + + @Throws(NotFoundException::class) + fun getDimension(@DimenRes id: Int): Float = baseResources.getDimension(id) + + @Throws(NotFoundException::class) + fun getColorStateList(@ColorRes id: Int): ColorStateList = baseResources.getColorStateList(id) + + @TargetApi(Build.VERSION_CODES.M) + fun getColorStateList(@ColorRes id: Int, theme: Resources.Theme?): ColorStateList = + baseResources.getColorStateList(id, theme) + + @Throws(NotFoundException::class) + fun getBoolean(@BoolRes id: Int): Boolean = baseResources.getBoolean(id) + + fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int = + baseResources.getIdentifier(name, defType, defPackage) + + @ColorInt + @Throws(NotFoundException::class) + fun getColor(@ColorRes id: Int): Int = baseResources.getColor(id) + + @TargetApi(Build.VERSION_CODES.M) + @ColorInt + @Throws(NotFoundException::class) + fun getColor(@ColorRes id: Int, theme: Resources.Theme?): Int = baseResources.getColor(id, theme) + + fun updateConfiguration(config: Configuration?, metrics: DisplayMetrics?) { + baseResources.updateConfiguration(config, metrics) + } + + @Throws(NotFoundException::class) + fun openRawResource(@RawRes id: Int): InputStream = baseResources.openRawResource(id) + + @Throws(NotFoundException::class) + fun openRawResource(@RawRes id: Int, value: TypedValue?): InputStream = + baseResources.openRawResource(id, value) + + @Throws(NotFoundException::class) + fun getMovie(@RawRes id: Int): Movie = baseResources.getMovie(id) + + @Throws(NotFoundException::class) + fun getInteger(@IntegerRes id: Int): Int = baseResources.getInteger(id) + + @Throws(XmlPullParserException::class, IOException::class) + fun parseBundleExtras(parser: XmlResourceParser?, outBundle: Bundle?) { + this.baseResources.parseBundleExtras(parser, outBundle) + } + + @Throws(NotFoundException::class) + fun getDrawable(@DrawableRes id: Int): Drawable = baseResources.getDrawable(id) + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Throws(NotFoundException::class) + fun getDrawable(@DrawableRes id: Int, theme: Resources.Theme?): Drawable = + baseResources.getDrawable(id, theme) + + @Throws(NotFoundException::class) + fun getResourceTypeName(@AnyRes resid: Int): String = baseResources.getResourceTypeName(resid) + + @Throws(NotFoundException::class) + fun getLayout(@LayoutRes id: Int): XmlResourceParser = baseResources.getLayout(id) + + @RequiresApi(Build.VERSION_CODES.O) + @SuppressLint("NewApi") + @Throws(NotFoundException::class) + fun getFont(@FontRes id: Int): Typeface = baseResources.getFont(id) + + @Throws(NotFoundException::class) + fun getXml(@XmlRes id: Int): XmlResourceParser = baseResources.getXml(id) + + @Throws(NotFoundException::class) + fun getResourceName(@AnyRes resid: Int): String = baseResources.getResourceName(resid) + + @Throws(XmlPullParserException::class) + fun parseBundleExtra(tagName: String?, attrs: AttributeSet?, outBundle: Bundle?) { + baseResources.parseBundleExtra(tagName, attrs, outBundle) + } + + @Throws(NotFoundException::class) + fun getDimensionPixelOffset(@DimenRes id: Int): Int = baseResources.getDimensionPixelOffset(id) + + @Throws(NotFoundException::class) + fun getValueForDensity( @AnyRes id: Int, density: Int, outValue: TypedValue?, resolveRefs: Boolean) { + baseResources.getValueForDensity(id, density, outValue, resolveRefs) + } + + @Throws(NotFoundException::class) + fun getResourceEntryName(@AnyRes resid: Int): String = baseResources.getResourceEntryName(resid) + + @Throws(NotFoundException::class) + fun getFraction(@FractionRes id: Int, base: Int, pbase: Int): Float = + baseResources.getFraction(id, base, pbase) + + private fun getFormattedText(format: String, vararg formatArgs: Any?) = + String.format(locale, format, *formatArgs) + + private fun getTextFromId(id: Int) = + (repository.getText(baseResources.getResourceEntryName(id)) + ?: baseResources.getText(id)) + + private fun getQuantityTextFromId(id: Int, quantity: Int): CharSequence = repository.getPlural( + baseResources.getResourceEntryName(id), + quantity.toPluralKeyword(baseResources, locale) + ) ?: baseResources.getQuantityText(id, quantity) + + private fun getTextArrayFromId(id: Int): Array = + repository.getTextArray(baseResources.getResourceEntryName(id)) + ?: baseResources.getTextArray(id) } interface PhilologyRepository { @@ -55,8 +250,9 @@ private fun Resources.currentLocale(): Locale = if (Build.VERSION.SDK_INT <= Bui configuration.locales[0] } -private fun Int.toPluralKeyword(baseResources: Resources): String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - PluralRules.forLocale(baseResources.currentLocale()).select(this.toDouble()) -} else { - baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, this) -} +private fun Int.toPluralKeyword(baseResources: Resources, locale: Locale): String = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + PluralRules.forLocale(locale).select(this.toDouble()) + } else { + baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, this) + } diff --git a/philology/src/test/java/com/jcminarro/philology/ResourcesUtilTest.kt b/philology/src/test/java/com/jcminarro/philology/ResourcesUtilTest.kt index 3e1243e..da787ee 100644 --- a/philology/src/test/java/com/jcminarro/philology/ResourcesUtilTest.kt +++ b/philology/src/test/java/com/jcminarro/philology/ResourcesUtilTest.kt @@ -1,31 +1,50 @@ package com.jcminarro.philology +import android.content.res.AssetFileDescriptor +import android.content.res.ColorStateList import android.content.res.Configuration import android.content.res.Resources +import android.content.res.TypedArray +import android.content.res.XmlResourceParser +import android.graphics.Movie +import android.graphics.Typeface +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.util.AttributeSet +import android.util.DisplayMetrics +import android.util.TypedValue import com.nhaarman.mockito_kotlin.doReturn +import com.nhaarman.mockito_kotlin.doThrow +import org.amshove.kluent.Verify import org.amshove.kluent.When +import org.amshove.kluent.`Verify no further interactions` import org.amshove.kluent.`should be equal to` import org.amshove.kluent.`should throw` +import org.amshove.kluent.called import org.amshove.kluent.calling import org.amshove.kluent.invoking import org.amshove.kluent.mock +import org.amshove.kluent.on +import org.amshove.kluent.that +import org.amshove.kluent.was import org.junit.Before import org.junit.Test -import java.util.Locale +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException +import java.io.InputStream class ResourcesUtilTest { - private var configuration: Configuration = createConfiguration() - private var quantity = 1 + private val configuration: Configuration = createConfiguration() private val baseResources: Resources = mock() - private val resources = ResourcesUtil(baseResources) - private val someCharSequence: CharSequence = "text" + private val resourcesUtil = ResourcesUtil(baseResources) + private val someCharSequence: CharSequence = randomString() private val someString: String = someCharSequence.toString() - private val repoCharSequence: CharSequence = "repo" + private val repoCharSequence: CharSequence = randomString() private val repoString: String = repoCharSequence.toString() - private val id = 0 - private val formatArg = "argument" - private val nameId = "nameId" + private val id = randomInt() + private val formatArg = randomString() + private val nameId = randomString() @Before fun setup() { @@ -36,251 +55,1284 @@ class ResourcesUtilTest { @Test fun `Should throw an exception if the given id doesn't exist asking for a text`() { configureResourceGetIdException(baseResources, id) - invoking { resources.getText(id) } `should throw` Resources.NotFoundException::class + + invoking { resourcesUtil.getText(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test fun `Should return a CharSequence asking for a text`() { configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getText(id) `should be equal to` someCharSequence + + val result = resourcesUtil.getText(id) + + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a CharSequence from repository asking for a text`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, repoCharSequence)) + + val result = resourcesUtil.getText(id) + + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a CharSequence asking for a text with default value`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + + val result = resourcesUtil.getText(id, randomString()) + + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a CharSequence from repository asking for a text with default value`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, repoCharSequence)) + + val result = resourcesUtil.getText(id, randomString()) + + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a the default CharSequence asking for a text`() { + val defaultCharSequence: CharSequence = randomString() + configureResourceGetIdException(baseResources, id) + + val result = resourcesUtil.getText(id, defaultCharSequence) + + result `should be equal to` defaultCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test fun `Should throw an exception if the given id doesn't exist asking for an String`() { configureResourceGetIdException(baseResources, id) - invoking { resources.getString(id) } `should throw` Resources.NotFoundException::class - } + + invoking { resourcesUtil.getString(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + } @Test fun `Should return a CharSequence asking for an String`() { configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getString(id) `should be equal to` someString + + val result = resourcesUtil.getString(id) + + result `should be equal to` someString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence from repository asking for a text`() { + fun `Should return a CharSequence from repository asking for an String`() { configureResourceGetText(baseResources, id, nameId, someCharSequence) configurePhilology(createRepository(nameId, null, repoCharSequence)) - resources.getText(id) `should be equal to` repoCharSequence + + val result = resourcesUtil.getString(id) + + result `should be equal to` repoString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence from repository asking for an String`() { + fun `Should throw an exception if the given id doesn't exist asking for a formatted String`() { + configureResourceGetIdException(baseResources, id) + + invoking { resourcesUtil.getString(id, formatArg) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a CharSequence asking for a formatted String`() { + configureResourceGetText(baseResources, id, nameId, "$someCharSequence%s") + + val result = resourcesUtil.getString(id, formatArg) + + result `should be equal to` "$someString$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a CharSequence from repository asking for a formatted String`() { configureResourceGetText(baseResources, id, nameId, someCharSequence) - configurePhilology(createRepository(nameId, null, repoCharSequence)) - resources.getString(id) `should be equal to` repoString + configurePhilology(createRepository(nameId, null, "$repoCharSequence%s")) + + val result = resourcesUtil.getString(id, formatArg) + + result `should be equal to` "$repoString$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test fun `Should throw an exception if the given id doesn't exist asking for a quantity text`() { configureResourceGetIdException(baseResources, id) - invoking { resources.getQuantityText(id, quantity) } `should throw` Resources.NotFoundException::class + + invoking { resourcesUtil.getQuantityText(id, randomInt()) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test fun `Should return a CharSequence asking for a quantity text`() { - configureResourceQuantityString(baseResources, quantity, "one") + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - resources.getQuantityText(id, quantity) `should be equal to` someCharSequence + + val result = resourcesUtil.getQuantityText(id, quantity) + + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return a CharSequence asking for a quantity text from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, repoCharSequence)) + + val result = resourcesUtil.getQuantityText(id, quantity) + + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + `Verify no further interactions` on baseResources } @Test fun `Should throw an exception if the given id doesn't exist asking for an quantity String`() { configureResourceGetIdException(baseResources, id) - invoking { resources.getQuantityString(id, quantity) } `should throw` Resources.NotFoundException::class + + invoking { resourcesUtil.getQuantityString(id, randomInt()) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test fun `Should return a CharSequence asking for an quantity String`() { - configureResourceQuantityString(baseResources, quantity, "one") + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - resources.getQuantityString(id, quantity) `should be equal to` someString + + val result = resourcesUtil.getQuantityString(id, quantity) + + result `should be equal to` someString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources } @Test - fun `Should throw an exception if id doesn't exist asking for an formatted quantity String`() { + fun `Should return a CharSequence asking for an quantity String from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, repoCharSequence)) + + val result = resourcesUtil.getQuantityString(id, quantity) + + result `should be equal to` repoString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if id doesn't exist asking for a formatted quantity String`() { configureResourceGetIdException(baseResources, id) - invoking { resources.getQuantityString(id, quantity, formatArg) } `should throw` Resources.NotFoundException::class + + invoking { resourcesUtil.getQuantityString(id, randomInt(), formatArg) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence asking for an formatted quantity String`() { - configureResourceQuantityString(baseResources, quantity, "one") + fun `Should return a CharSequence asking for a formatted quantity String`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) configureResourceGetQuantityText(baseResources, id, nameId, quantity, "$someCharSequence%s") - resources.getQuantityString(id, quantity, formatArg) `should be equal to` someString + formatArg + + val result = resourcesUtil.getQuantityString(id, quantity, formatArg) + + result `should be equal to` someString + formatArg + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for zero keyword asking for a quantity text`() { - quantity = 0 - val locale = Locale("ar", "ME") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "zero") + fun `Should return a CharSequence asking for a formatted quantity text from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "zero", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoCharSequence + configurePhilology(createRepository(nameId, quantityString, "$repoCharSequence%s")) + + val result = resourcesUtil.getQuantityString(id, quantity, formatArg) + + result `should be equal to` "$repoCharSequence$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for zero keyword asking for an quantity String`() { - quantity = 0 - val locale = Locale("ar", "ME") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "zero") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "zero", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoString + fun `Should throw an exception if the given id doesn't exist asking for text array`() { + configureResourceGetIdException(baseResources, id) + + invoking { resourcesUtil.getTextArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for one keyword asking for a quantity text`() { - quantity = 1 - configureResourceQuantityString(baseResources, quantity, "one") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "one", repoCharSequence)) - resources.getQuantityText(id, quantity) `should be equal to` repoCharSequence + fun `Should return an array of strings asking for a text array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + configureResourceGetTextArray(baseResources, id, nameId, textArray) + + val result = resourcesUtil.getTextArray(id) + + result `should be equal to` textArray + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getTextArray(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for one keyword asking for an quantity String`() { - quantity = 1 - configureResourceQuantityString(baseResources, quantity, "one") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "one", repoCharSequence)) - resources.getQuantityText(id, quantity) `should be equal to` repoString + fun `Should return an array of strings from repository asking for a text array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + configureResourceGetTextArray(baseResources, id, nameId, arrayOf(randomString(), randomString())) + configurePhilology(createRepository(nameId, textArray = textArray)) + + val result = resourcesUtil.getTextArray(id) + + result `should be equal to` textArray + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for two keyword asking for a quantity text`() { - quantity = 2 - val locale = Locale("ar", "ME") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "two") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "two", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoCharSequence + fun `Should throw an exception if the given id doesn't exist asking for a string array`() { + configureResourceGetIdException(baseResources, id) + + invoking { resourcesUtil.getStringArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for two keyword asking for an quantity String`() { - quantity = 2 - val locale = Locale("ar", "ME") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "two") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "two", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoString + fun `Should return an array of strings asking for a string array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + val expectedResult = textArray.map { it.toString() }.toTypedArray() + configureResourceGetTextArray(baseResources, id, nameId, textArray) + + val result = resourcesUtil.getStringArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getTextArray(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for few keyword asking for a quantity text`() { - quantity = 2 - val locale = Locale("ru", "RU") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "few") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "few", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoCharSequence + fun `Should return an array of strings from repository asking for a string array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + val expectedResult = textArray.map { it.toString() }.toTypedArray() + configureResourceGetTextArray(baseResources, id, nameId, arrayOf(randomString(), randomString())) + configurePhilology(createRepository(nameId, textArray = textArray)) + + val result = resourcesUtil.getStringArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for few keyword asking for an quantity String`() { - quantity = 2 - val locale = Locale("ru", "RU") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "few") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "few", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoString + fun `Should throw an exception if the given id doesn't exist calling getAnimation`() { + val id = randomInt() + When calling baseResources.getAnimation(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getAnimation(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getAnimation(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for many keyword asking for a quantity text`() { - quantity = 5 - val locale = Locale("ru", "RU") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "many") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "many", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoCharSequence + fun `Should return animation calling getAnimation`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getAnimation(id) doReturn expectedResult + + val result = resourcesUtil.getAnimation(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getAnimation(id) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for many keyword asking for an quantity String`() { - quantity = 5 - val locale = Locale("ru", "RU") - configuration = createConfiguration(locale) - setup() - configureResourceQuantityString(baseResources, quantity, "many") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "many", repoCharSequence), locale) - resources.getQuantityText(id, quantity) `should be equal to` repoString + fun `Should return displayMetrics calling getDisplayMetrics`() { + val expectedResult: DisplayMetrics = mock() + When calling baseResources.displayMetrics doReturn expectedResult + + val result = resourcesUtil.getDisplayMetrics() + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.displayMetrics was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for other keyword asking for a quantity text`() { - quantity = 2 - configureResourceQuantityString(baseResources, quantity, "other") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "other", repoCharSequence)) - resources.getQuantityText(id, quantity) `should be equal to` repoCharSequence + fun `Should throw an exception if the given id doesn't exist calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + When calling baseResources.getDrawableForDensity(id, density) doThrow Resources + .NotFoundException::class + + invoking { resourcesUtil.getDrawableForDensity(id, density) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawableForDensity(id, density) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return a CharSequence for other keyword asking for an quantity String`() { - quantity = 2 - configureResourceQuantityString(baseResources, quantity, "other") - configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - configurePhilology(createRepository(nameId, "other", repoCharSequence)) - resources.getQuantityText(id, quantity) `should be equal to` repoString + fun `Should return Drawable calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawableForDensity(id, density) doReturn expectedResult + + val result = resourcesUtil.getDrawableForDensity(id, density) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawableForDensity(id, density) was called + `Verify no further interactions` on baseResources } @Test - fun `Should throw an exception if the given id doesn't exist asking for text array`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getTextArray(id) } `should throw` Resources.NotFoundException::class + fun `Should throw an exception if the given id doesn't exist calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getDrawableForDensity(id, density, theme) doThrow Resources + .NotFoundException::class + + invoking { resourcesUtil.getDrawableForDensity(id, density, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawableForDensity(id, density, theme) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return an array of strings asking for a text array`() { - val textArray: Array = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - resources.getTextArray(id) `should be equal to` textArray + fun `Should return Drawable calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawableForDensity(id, density, theme) doReturn expectedResult + + val result = resourcesUtil.getDrawableForDensity(id, density, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawableForDensity(id, density, theme) was called + `Verify no further interactions` on baseResources } @Test - fun `Should throw an exception if the given id doesn't exist asking for a string array`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getStringArray(id) } `should throw` Resources.NotFoundException::class + fun `Should return configuration calling getConfiguration`() { + val result = resourcesUtil.getConfiguration() + + result `should be equal to` configuration + Verify on baseResources that baseResources.configuration was called + `Verify no further interactions` on baseResources } @Test - fun `Should return an array of strings asking for a string array`() { - val textArray: Array = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - resources.getStringArray(id) `should be equal to` textArray.map { it.toString() }.toTypedArray() + fun `Should throw an exception calling obtainAttributes`() { + val set: AttributeSet = mock() + val attrs: IntArray = intArrayOf(randomInt()) + When calling baseResources.obtainAttributes(set, attrs) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.obtainAttributes(set, attrs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.obtainAttributes(set, attrs) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return an array of strings from repository asking for a text array`() { - val textArray: Array = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - configurePhilology(createRepository(nameId, textArray = textArray)) - resources.getTextArray(id) `should be equal to` textArray + fun `Should return animation calling obtainAttributes`() { + val set: AttributeSet = mock() + val attrs: IntArray = intArrayOf(randomInt()) + val expectedResult: TypedArray = mock() + When calling baseResources.obtainAttributes(set, attrs) doReturn expectedResult + + val result = resourcesUtil.obtainAttributes(set, attrs) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.obtainAttributes(set, attrs) was called + `Verify no further interactions` on baseResources } @Test - fun `Should return an array of strings from repository asking for a string array`() { - val textArray: Array = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - configurePhilology(createRepository(nameId, textArray = textArray)) - resources.getStringArray(id) `should be equal to` textArray.map { it.toString() }.toTypedArray() + fun `Should throw an exception if the given id doesn't exist calling obtainTypedArray`() { + val id = randomInt() + When calling baseResources.obtainTypedArray(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.obtainTypedArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.obtainTypedArray(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return TypedArray calling obtainTypedArray`() { + val id = randomInt() + val expectedResult: TypedArray = mock() + When calling baseResources.obtainTypedArray(id) doReturn expectedResult + + val result = resourcesUtil.obtainTypedArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.obtainTypedArray(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimensionPixelSize`() { + val id = randomInt() + When calling baseResources.getDimensionPixelSize(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getDimensionPixelSize(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimensionPixelSize(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return dimension calling getDimensionPixelSize`() { + val id = randomInt() + val expectedResult: Int = randomInt() + When calling baseResources.getDimensionPixelSize(id) doReturn expectedResult + + val result = resourcesUtil.getDimensionPixelSize(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimensionPixelSize(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getIntArray`() { + val id = randomInt() + When calling baseResources.getIntArray(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getIntArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getIntArray(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return intArray calling getIntArray`() { + val id = randomInt() + val expectedResult: IntArray = intArrayOf(randomInt(), randomInt(), randomInt()) + When calling baseResources.getIntArray(id) doReturn expectedResult + + val result = resourcesUtil.getIntArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getIntArray(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getValue`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValue(id, typedValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getValue(id, typedValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValue(id, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return value calling getValue`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + resourcesUtil.getValue(id, typedValue, resolveRefs) + + Verify on baseResources that baseResources.getValue(id, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given name doesn't exist calling getValue`() { + val name = randomString() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValue(name, typedValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getValue(name, typedValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValue(name, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return value calling getValue`() { + val name = randomString() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + resourcesUtil.getValue(name, typedValue, resolveRefs) + + Verify on baseResources that baseResources.getValue(name, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourcePackageName`() { + val id = randomInt() + When calling baseResources.getResourcePackageName(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getResourcePackageName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourcePackageName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return package calling getResourcePackageName`() { + val id = randomInt() + val expectedResult: String = randomString() + When calling baseResources.getResourcePackageName(id) doReturn expectedResult + + val result = resourcesUtil.getResourcePackageName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourcePackageName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResourceFd`() { + val id = randomInt() + When calling baseResources.openRawResourceFd(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.openRawResourceFd(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.openRawResourceFd(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return assetFileDescriptor calling openRawResourceFd`() { + val id = randomInt() + val expectedResult: AssetFileDescriptor = mock() + When calling baseResources.openRawResourceFd(id) doReturn expectedResult + + val result = resourcesUtil.openRawResourceFd(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResourceFd(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimension`() { + val id = randomInt() + When calling baseResources.getDimension(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getDimension(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimension(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return dimension calling getDimension`() { + val id = randomInt() + val expectedResult = randomFloat() + When calling baseResources.getDimension(id) doReturn expectedResult + + val result = resourcesUtil.getDimension(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimension(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColorStateList`() { + val id = randomInt() + When calling baseResources.getColorStateList(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getColorStateList(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColorStateList(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return colorStateList calling getColorStateList`() { + val id = randomInt() + val expectedResult: ColorStateList = mock() + When calling baseResources.getColorStateList(id) doReturn expectedResult + + val result = resourcesUtil.getColorStateList(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColorStateList(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColorStateList`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getColorStateList(id, theme) doThrow Resources + .NotFoundException::class + + invoking { resourcesUtil.getColorStateList(id, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getColorStateList(id, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return colorStateList calling getColorStateList`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: ColorStateList = mock() + When calling baseResources.getColorStateList(id, theme) doReturn expectedResult + + val result = resourcesUtil.getColorStateList(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColorStateList(id, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getBoolean`() { + val id = randomInt() + When calling baseResources.getBoolean(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getBoolean(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getBoolean(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return boolean calling getBoolean`() { + val id = randomInt() + val expectedResult = randomBoolean() + When calling baseResources.getBoolean(id) doReturn expectedResult + + val result = resourcesUtil.getBoolean(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getBoolean(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getIdentifier`() { + val name = randomString() + val defType = randomString() + val defPackage = randomString() + When calling baseResources.getIdentifier(name, defType, defPackage) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getIdentifier(name, defType, defPackage) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getIdentifier(name, defType, defPackage) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return integer calling getIdentifier`() { + val name = randomString() + val defType = randomString() + val defPackage = randomString() + val expectedResult = randomInt() + When calling baseResources.getIdentifier(name, defType, defPackage) doReturn expectedResult + + val result = resourcesUtil.getIdentifier(name, defType, defPackage) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getIdentifier(name, defType, defPackage) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColor`() { + val id = randomInt() + When calling baseResources.getColor(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getColor(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColor(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return color calling getColor`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getColor(id) doReturn expectedResult + + val result = resourcesUtil.getColor(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColor(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColor`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getColor(id, theme) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getColor(id, theme) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColor(id, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return color calling getColor`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult = randomInt() + When calling baseResources.getColor(id, theme) doReturn expectedResult + + val result = resourcesUtil.getColor(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColor(id, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should call to updateConfiguration`() { + val newConf: Configuration = mock() + val newMetrics: DisplayMetrics = mock() + + resourcesUtil.updateConfiguration(newConf, newMetrics) + + Verify on baseResources that baseResources.updateConfiguration(newConf, newMetrics) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResource`() { + val id = randomInt() + When calling baseResources.openRawResource(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.openRawResource(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.openRawResource(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return inputStream calling openRawResource`() { + val id = randomInt() + val expectedResult: InputStream = mock() + When calling baseResources.openRawResource(id) doReturn expectedResult + + val result = resourcesUtil.openRawResource(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResource(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResource`() { + val id = randomInt() + val typedValue: TypedValue = mock() + When calling baseResources.openRawResource(id, typedValue) doThrow Resources + .NotFoundException::class + + invoking { resourcesUtil.openRawResource(id, typedValue) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.openRawResource(id, typedValue) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return inputStream calling openRawResource`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val expectedResult: InputStream = mock() + When calling baseResources.openRawResource(id, typedValue) doReturn expectedResult + + val result = resourcesUtil.openRawResource(id, typedValue) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResource(id, typedValue) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getMovie`() { + val id = randomInt() + When calling baseResources.getMovie(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getMovie(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getMovie(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Movie calling getMovie`() { + val id = randomInt() + val expectedResult: Movie = mock() + When calling baseResources.getMovie(id) doReturn expectedResult + + val result = resourcesUtil.getMovie(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getMovie(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getInteger`() { + val id = randomInt() + When calling baseResources.getInteger(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getInteger(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getInteger(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Integer calling getInteger`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getInteger(id) doReturn expectedResult + + val result = resourcesUtil.getInteger(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getInteger(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an XmlPullParserException if the given id doesn't exist calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtras(parser, outBundle) doThrow XmlPullParserException::class + + invoking { resourcesUtil.parseBundleExtras(parser, outBundle) } `should throw` XmlPullParserException::class + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an IOException if the given id doesn't exist calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtras(parser, outBundle) doThrow IOException::class + + invoking { resourcesUtil.parseBundleExtras(parser, outBundle) } `should throw` IOException::class + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Integer calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + + resourcesUtil.parseBundleExtras(parser, outBundle) + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawable`() { + val id = randomInt() + When calling baseResources.getDrawable(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getDrawable(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDrawable(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Drawable calling getDrawable`() { + val id = randomInt() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawable(id) doReturn expectedResult + + val result = resourcesUtil.getDrawable(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawable(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawable`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getDrawable(id, theme) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getDrawable(id, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawable(id, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Drawable calling getDrawable`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawable(id, theme) doReturn expectedResult + + val result = resourcesUtil.getDrawable(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawable(id, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceTypeName`() { + val id = randomInt() + When calling baseResources.getResourceTypeName(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getResourceTypeName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceTypeName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Name calling getResourceTypeName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceTypeName(id) doReturn expectedResult + + val result = resourcesUtil.getResourceTypeName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceTypeName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getLayout`() { + val id = randomInt() + When calling baseResources.getLayout(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getLayout(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getLayout(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return layout calling getLayout`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getLayout(id) doReturn expectedResult + + val result = resourcesUtil.getLayout(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getLayout(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getFont`() { + val id = randomInt() + When calling baseResources.getFont(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getFont(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getFont(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return typeFace calling getFont`() { + val id = randomInt() + val expectedResult: Typeface = mock() + When calling baseResources.getFont(id) doReturn expectedResult + + val result = resourcesUtil.getFont(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getFont(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getXml`() { + val id = randomInt() + When calling baseResources.getXml(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getXml(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getXml(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return xml calling getXml`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getXml(id) doReturn expectedResult + + val result = resourcesUtil.getXml(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getXml(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceName`() { + val id = randomInt() + When calling baseResources.getResourceName(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getResourceName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Name calling getResourceName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceName(id) doReturn expectedResult + + val result = resourcesUtil.getResourceName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling parseBundleExtra`() { + val tagName: String = randomString() + val attrs: AttributeSet = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtra(tagName, attrs, outBundle) doThrow XmlPullParserException::class + + invoking { resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) } `should throw` XmlPullParserException::class + + Verify on baseResources that baseResources.parseBundleExtra(tagName, attrs, outBundle) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Name calling parseBundleExtra`() { + val tagName: String = randomString() + val attrs: AttributeSet = mock() + val outBundle: Bundle = mock() + + resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) + + Verify on baseResources that baseResources.parseBundleExtra(tagName, attrs, outBundle) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimensionPixelOffset`() { + val id = randomInt() + When calling baseResources.getDimensionPixelOffset(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getDimensionPixelOffset(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimensionPixelOffset(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Integer calling getDimensionPixelOffset`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getDimensionPixelOffset(id) doReturn expectedResult + + val result = resourcesUtil.getDimensionPixelOffset(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimensionPixelOffset(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getValueForDensity`() { + val id = randomInt() + val density = randomInt() + val outValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValueForDensity(id, density, outValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValueForDensity(id, density, outValue, resolveRefs) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Drawable calling getValueForDensity`() { + val id = randomInt() + val density = randomInt() + val outValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) + + Verify on baseResources that baseResources.getValueForDensity(id, density, outValue, resolveRefs) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceEntryName`() { + val id = randomInt() + When calling baseResources.getResourceEntryName(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getResourceEntryName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return Name calling getResourceEntryName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceEntryName(id) doReturn expectedResult + + val result = resourcesUtil.getResourceEntryName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getFraction`() { + val id = randomInt() + val base = randomInt() + val pbase = randomInt() + When calling baseResources.getFraction(id, base, pbase) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.getFraction(id, base, pbase) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getFraction(id, base, pbase) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return dimension calling getFraction`() { + val id = randomInt() + val base = randomInt() + val pbase = randomInt() + val expectedResult = randomFloat() + When calling baseResources.getFraction(id, base, pbase) doReturn expectedResult + + val result = resourcesUtil.getFraction(id, base, pbase) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getFraction(id, base, pbase) was called + `Verify no further interactions` on baseResources } } From 21f06656a09abfeb00cea208bb9685b73c170461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jc=20Mi=C3=B1arro?= Date: Sat, 1 Feb 2020 10:21:46 +0100 Subject: [PATCH 3/5] Create a test double for Handler --- philology/src/test/java/android/os/Handler.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 philology/src/test/java/android/os/Handler.java diff --git a/philology/src/test/java/android/os/Handler.java b/philology/src/test/java/android/os/Handler.java new file mode 100644 index 0000000..86cc004 --- /dev/null +++ b/philology/src/test/java/android/os/Handler.java @@ -0,0 +1,9 @@ +package android.os; + +public class Handler { + + public final boolean post(Runnable r) { + r.run(); + return true; + } +} From 51bca7766df39eff6a4cc06ba9d7097f51e3ebcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jc=20Mi=C3=B1arro?= Date: Sat, 1 Feb 2020 10:30:49 +0100 Subject: [PATCH 4/5] Refactor PhilologyResources --- .../philology/PhilologyContextWrapper.kt | 2 +- .../jcminarro/philology/PhilologyResources.kt | 266 +-- .../philology/PhilologyResourcesTest.kt | 1803 +++++++++++++---- 3 files changed, 1606 insertions(+), 465 deletions(-) diff --git a/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt b/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt index 6d5c5b5..d647d88 100644 --- a/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt +++ b/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt @@ -14,7 +14,7 @@ internal class PhilologyContextWrapper(base: Context) : ContextWrapper(base) { if (VectorEnabledTintResources.shouldBeUsed()) { PhilologyVectorEnabledTintResources(this, baseResources) } else { - PhilologyResources(baseResources) + PhilologyResources(ResourcesUtil(baseResources)) } } diff --git a/philology/src/main/java/com/jcminarro/philology/PhilologyResources.kt b/philology/src/main/java/com/jcminarro/philology/PhilologyResources.kt index 70adeb7..631ab26 100644 --- a/philology/src/main/java/com/jcminarro/philology/PhilologyResources.kt +++ b/philology/src/main/java/com/jcminarro/philology/PhilologyResources.kt @@ -11,176 +11,206 @@ import android.content.res.XmlResourceParser import android.graphics.Movie import android.graphics.Typeface import android.graphics.drawable.Drawable -import android.os.Build.VERSION_CODES +import android.os.Build import android.os.Bundle +import android.os.Handler import android.util.AttributeSet import android.util.DisplayMetrics import android.util.TypedValue +import androidx.annotation.AnimRes +import androidx.annotation.AnimatorRes +import androidx.annotation.AnyRes +import androidx.annotation.ArrayRes +import androidx.annotation.BoolRes +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.annotation.DimenRes +import androidx.annotation.DrawableRes +import androidx.annotation.FontRes +import androidx.annotation.FractionRes +import androidx.annotation.IntegerRes +import androidx.annotation.LayoutRes +import androidx.annotation.PluralsRes +import androidx.annotation.RawRes import androidx.annotation.RequiresApi +import androidx.annotation.StringRes +import androidx.annotation.StyleableRes +import androidx.annotation.XmlRes import org.xmlpull.v1.XmlPullParserException import java.io.IOException import java.io.InputStream @Suppress("DEPRECATION") -internal class PhilologyResources( - private val baseResources: Resources -) : Resources(baseResources.assets, baseResources.displayMetrics, baseResources.configuration) { - private val resourcesUtil = ResourcesUtil(baseResources) +internal class PhilologyResources(private val resourcesUtil: ResourcesUtil) : + Resources(resourcesUtil.baseResources.assets, + resourcesUtil.baseResources.displayMetrics, + resourcesUtil.baseResources.configuration) { - override fun getText(id: Int): CharSequence = resourcesUtil.getText(id) + @Throws(NotFoundException::class) + override fun getText(@StringRes id: Int): CharSequence = resourcesUtil.getText(id) - override fun getText(id: Int, def: CharSequence): CharSequence = try { - getText(id) - } catch (_: NotFoundException) { - def - } + override fun getText(@StringRes id: Int, def: CharSequence): CharSequence = resourcesUtil.getText(id, def) - override fun getString(id: Int): String = resourcesUtil.getString(id) + @Throws(NotFoundException::class) + override fun getString(@StringRes id: Int): String = resourcesUtil.getString(id) - override fun getQuantityText(id: Int, quantity: Int): CharSequence = - resourcesUtil.getQuantityText(id, quantity) + @Throws(NotFoundException::class) + override fun getString(@StringRes id: Int, vararg formatArgs: Any?): String = + resourcesUtil.getString(id, *formatArgs) - override fun getQuantityString(id: Int, quantity: Int): String = - resourcesUtil.getQuantityString(id, quantity) + @Throws(NotFoundException::class) + override fun getQuantityText(@PluralsRes id: Int, quantity: Int): CharSequence = + resourcesUtil.getQuantityText(id, quantity) - override fun getQuantityString(id: Int, quantity: Int, vararg formatArgs: Any?): String = - resourcesUtil.getQuantityString(id, quantity, *formatArgs) + @Throws(NotFoundException::class) + override fun getQuantityString(@PluralsRes id: Int, quantity: Int): String = + resourcesUtil.getQuantityString(id, quantity) - override fun getStringArray(id: Int): Array = resourcesUtil.getStringArray(id) + @Throws(NotFoundException::class) + override fun getQuantityString(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any?): String = + resourcesUtil.getQuantityString(id, quantity, *formatArgs) - override fun getTextArray(id: Int): Array = resourcesUtil.getTextArray(id) + @Throws(NotFoundException::class) + override fun getTextArray(@ArrayRes id: Int): Array = resourcesUtil.getTextArray(id) - @Throws(NotFoundException::class) - override fun getAnimation(id: Int): XmlResourceParser = baseResources.getAnimation(id) + @Throws(NotFoundException::class) + override fun getStringArray(@ArrayRes id: Int): Array = resourcesUtil.getStringArray(id) - override fun getDisplayMetrics(): DisplayMetrics = baseResources.displayMetrics + @Throws(NotFoundException::class) + override fun getAnimation(@AnimatorRes @AnimRes id: Int): XmlResourceParser = resourcesUtil.getAnimation(id) - override fun getDrawableForDensity(id: Int, density: Int): Drawable? = - baseResources.getDrawableForDensity(id, density) + override fun getDisplayMetrics(): DisplayMetrics = resourcesUtil.getDisplayMetrics() - @TargetApi(VERSION_CODES.LOLLIPOP) - override fun getDrawableForDensity(id: Int, density: Int, theme: Theme?): Drawable? = - baseResources.getDrawableForDensity(id, density, theme) + @Throws(NotFoundException::class) + override fun getDrawableForDensity(@DrawableRes id: Int, density: Int): Drawable? = + resourcesUtil.getDrawableForDensity(id, density) - override fun getConfiguration(): Configuration = baseResources.configuration + @Throws(NotFoundException::class) + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + override fun getDrawableForDensity(@DrawableRes id: Int, density: Int, theme: Theme?): Drawable? = + resourcesUtil.getDrawableForDensity(id, density, theme) - override fun obtainAttributes(set: AttributeSet?, attrs: IntArray?): TypedArray { - return baseResources.obtainAttributes(set, attrs) - } + override fun getConfiguration(): Configuration = resourcesUtil.getConfiguration() - @Throws(NotFoundException::class) - override fun getDimensionPixelSize(id: Int): Int = baseResources.getDimensionPixelSize(id) + override fun obtainAttributes(set: AttributeSet?, @StyleableRes attrs: IntArray?): TypedArray = + resourcesUtil.obtainAttributes(set, attrs) - @Throws(NotFoundException::class) - override fun getIntArray(id: Int): IntArray = baseResources.getIntArray(id) + @Throws(NotFoundException::class) + override fun obtainTypedArray(@ArrayRes id: Int): TypedArray = resourcesUtil.obtainTypedArray(id) - @Throws(NotFoundException::class) - override fun getValue(id: Int, outValue: TypedValue?, resolveRefs: Boolean) { - baseResources.getValue(id, outValue, resolveRefs) - } + @Throws(NotFoundException::class) + override fun getDimensionPixelSize(@DimenRes id: Int): Int = resourcesUtil.getDimensionPixelSize(id) - @Throws(NotFoundException::class) - override fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean) { - baseResources.getValue(name, outValue, resolveRefs) - } + @Throws(NotFoundException::class) + override fun getIntArray(@ArrayRes id: Int): IntArray = resourcesUtil.getIntArray(id) - @Throws(NotFoundException::class) - override fun getResourcePackageName(resid: Int): String = - baseResources.getResourcePackageName(resid) + @Throws(NotFoundException::class) + override fun getValue(@AnyRes id: Int, outValue: TypedValue?, resolveRefs: Boolean) { + resourcesUtil.getValue(id, outValue, resolveRefs) + } - @Throws(NotFoundException::class) - override fun openRawResourceFd(id: Int): AssetFileDescriptor = - baseResources.openRawResourceFd(id) + @Throws(NotFoundException::class) + override fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean) { + resourcesUtil.getValue(name, outValue, resolveRefs) + } - @Throws(NotFoundException::class) - override fun getDimension(id: Int): Float = baseResources.getDimension(id) + @Throws(NotFoundException::class) + override fun getResourcePackageName(@AnyRes resid: Int): String = + resourcesUtil.getResourcePackageName(resid) - @Throws(NotFoundException::class) - override fun getColorStateList(id: Int): ColorStateList = baseResources.getColorStateList(id) + @Throws(NotFoundException::class) + override fun openRawResourceFd(@RawRes id: Int): AssetFileDescriptor = + resourcesUtil.openRawResourceFd(id) - @TargetApi(VERSION_CODES.M) - @Throws(NotFoundException::class) - override fun getColorStateList(id: Int, theme: Theme?): ColorStateList = - baseResources.getColorStateList(id, theme) + @Throws(NotFoundException::class) + override fun getDimension(@DimenRes id: Int): Float = resourcesUtil.getDimension(id) - @Throws(NotFoundException::class) - override fun getBoolean(id: Int): Boolean = baseResources.getBoolean(id) + @Throws(NotFoundException::class) + override fun getColorStateList(@ColorRes id: Int): ColorStateList = resourcesUtil.getColorStateList(id) - override fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int = - baseResources.getIdentifier(name, defType, defPackage) + @TargetApi(Build.VERSION_CODES.M) + override fun getColorStateList(@ColorRes id: Int, theme: Theme?): ColorStateList = + resourcesUtil.getColorStateList(id, theme) - @Throws(NotFoundException::class) - override fun getColor(id: Int): Int = baseResources.getColor(id) + @Throws(NotFoundException::class) + override fun getBoolean(@BoolRes id: Int): Boolean = resourcesUtil.getBoolean(id) - @TargetApi(VERSION_CODES.M) - @Throws(NotFoundException::class) - override fun getColor(id: Int, theme: Theme?): Int = baseResources.getColor(id, theme) + override fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int = + resourcesUtil.getIdentifier(name, defType, defPackage) - override fun openRawResource(id: Int): InputStream = baseResources.openRawResource(id) + @ColorInt + @Throws(NotFoundException::class) + override fun getColor(@ColorRes id: Int): Int = resourcesUtil.getColor(id) - @Throws(NotFoundException::class) - override fun openRawResource(id: Int, value: TypedValue?): InputStream = - baseResources.openRawResource(id, value) + @TargetApi(Build.VERSION_CODES.M) + @ColorInt + @Throws(NotFoundException::class) + override fun getColor(@ColorRes id: Int, theme: Theme?): Int = resourcesUtil.getColor(id, theme) - @Throws(NotFoundException::class) - override fun getMovie(id: Int): Movie = baseResources.getMovie(id) + override fun updateConfiguration(config: Configuration?, metrics: DisplayMetrics?) { + Handler().post { resourcesUtil.updateConfiguration(config, metrics) } + } - @Throws(NotFoundException::class) - override fun getInteger(id: Int): Int = baseResources.getInteger(id) + @Throws(NotFoundException::class) + override fun openRawResource(@RawRes id: Int): InputStream = resourcesUtil.openRawResource(id) - @Throws(XmlPullParserException::class, IOException::class) - override fun parseBundleExtras(parser: XmlResourceParser?, outBundle: Bundle?) { - this.baseResources.parseBundleExtras(parser, outBundle) - } + @Throws(NotFoundException::class) + override fun openRawResource(@RawRes id: Int, value: TypedValue?): InputStream = + resourcesUtil.openRawResource(id, value) - @Throws(NotFoundException::class) - override fun getDrawable(id: Int): Drawable = baseResources.getDrawable(id) + @Throws(NotFoundException::class) + override fun getMovie(@RawRes id: Int): Movie = resourcesUtil.getMovie(id) - @TargetApi(VERSION_CODES.LOLLIPOP) - @Throws(NotFoundException::class) - override fun getDrawable(id: Int, theme: Theme?): Drawable = - baseResources.getDrawable(id, theme) + @Throws(NotFoundException::class) + override fun getInteger(@IntegerRes id: Int): Int = resourcesUtil.getInteger(id) - @Throws(NotFoundException::class) - override fun getResourceTypeName(resid: Int): String = baseResources.getResourceTypeName(resid) + @Throws(XmlPullParserException::class, IOException::class) + override fun parseBundleExtras(parser: XmlResourceParser?, outBundle: Bundle?) { + this.resourcesUtil.parseBundleExtras(parser, outBundle) + } - @Throws(NotFoundException::class) - override fun getLayout(id: Int): XmlResourceParser = baseResources.getLayout(id) + @Throws(NotFoundException::class) + override fun getDrawable(@DrawableRes id: Int): Drawable = resourcesUtil.getDrawable(id) - @SuppressLint("NewApi") - @RequiresApi(VERSION_CODES.O) - @Throws(NotFoundException::class) - override fun getFont(id: Int): Typeface = baseResources.getFont(id) + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Throws(NotFoundException::class) + override fun getDrawable(@DrawableRes id: Int, theme: Theme?): Drawable = + resourcesUtil.getDrawable(id, theme) - @Throws(NotFoundException::class) - override fun getXml(id: Int): XmlResourceParser = baseResources.getXml(id) + @Throws(NotFoundException::class) + override fun getResourceTypeName(@AnyRes resid: Int): String = resourcesUtil.getResourceTypeName(resid) - @Throws(NotFoundException::class) - override fun getResourceName(resid: Int): String = baseResources.getResourceName(resid) + @Throws(NotFoundException::class) + override fun getLayout(@LayoutRes id: Int): XmlResourceParser = resourcesUtil.getLayout(id) - @Throws(XmlPullParserException::class) - override fun parseBundleExtra(tagName: String?, attrs: AttributeSet?, outBundle: Bundle?) { - baseResources.parseBundleExtra(tagName, attrs, outBundle) - } + @RequiresApi(Build.VERSION_CODES.O) + @SuppressLint("NewApi") + @Throws(NotFoundException::class) + override fun getFont(@FontRes id: Int): Typeface = resourcesUtil.getFont(id) - @Throws(NotFoundException::class) - override fun getDimensionPixelOffset(id: Int): Int = baseResources.getDimensionPixelOffset(id) + @Throws(NotFoundException::class) + override fun getXml(@XmlRes id: Int): XmlResourceParser = resourcesUtil.getXml(id) - @Throws(NotFoundException::class) - override fun getValueForDensity( - id: Int, - density: Int, - outValue: TypedValue?, - resolveRefs: Boolean - ) { - baseResources.getValueForDensity(id, density, outValue, resolveRefs) - } + @Throws(NotFoundException::class) + override fun getResourceName(@AnyRes resid: Int): String = resourcesUtil.getResourceName(resid) - @Throws(NotFoundException::class) - override fun getResourceEntryName(resid: Int): String = - baseResources.getResourceEntryName(resid) + @Throws(XmlPullParserException::class) + override fun parseBundleExtra(tagName: String?, attrs: AttributeSet?, outBundle: Bundle?) { + resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) + } - @Throws(NotFoundException::class) - override fun getFraction(id: Int, base: Int, pbase: Int): Float = - baseResources.getFraction(id, base, pbase) + @Throws(NotFoundException::class) + override fun getDimensionPixelOffset(@DimenRes id: Int): Int = resourcesUtil.getDimensionPixelOffset(id) + + @Throws(NotFoundException::class) + override fun getValueForDensity(@AnyRes id: Int, density: Int, outValue: TypedValue?, resolveRefs: Boolean) { + resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) + } + + @Throws(NotFoundException::class) + override fun getResourceEntryName(@AnyRes resid: Int): String = resourcesUtil.getResourceEntryName(resid) + + @Throws(NotFoundException::class) + override fun getFraction(@FractionRes id: Int, base: Int, pbase: Int): Float = + resourcesUtil.getFraction(id, base, pbase) } diff --git a/philology/src/test/java/com/jcminarro/philology/PhilologyResourcesTest.kt b/philology/src/test/java/com/jcminarro/philology/PhilologyResourcesTest.kt index 4d4e2d5..7a4291e 100644 --- a/philology/src/test/java/com/jcminarro/philology/PhilologyResourcesTest.kt +++ b/philology/src/test/java/com/jcminarro/philology/PhilologyResourcesTest.kt @@ -4,7 +4,6 @@ import android.content.res.AssetFileDescriptor import android.content.res.ColorStateList import android.content.res.Configuration import android.content.res.Resources -import android.content.res.Resources.Theme import android.content.res.TypedArray import android.content.res.XmlResourceParser import android.graphics.Movie @@ -15,28 +14,42 @@ import android.util.AttributeSet import android.util.DisplayMetrics import android.util.TypedValue import com.nhaarman.mockito_kotlin.doReturn -import com.nhaarman.mockito_kotlin.verify +import com.nhaarman.mockito_kotlin.doThrow +import com.nhaarman.mockito_kotlin.spy +import org.amshove.kluent.Verify import org.amshove.kluent.When +import org.amshove.kluent.`Verify no further interactions` import org.amshove.kluent.`should be equal to` import org.amshove.kluent.`should throw` +import org.amshove.kluent.called import org.amshove.kluent.calling import org.amshove.kluent.invoking import org.amshove.kluent.mock +import org.amshove.kluent.on +import org.amshove.kluent.that +import org.amshove.kluent.was import org.junit.Before import org.junit.Test +import org.mockito.Mockito +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException import java.io.InputStream class PhilologyResourcesTest { - private val baseResources: Resources = mock() - private val configuration: Configuration = createConfiguration() - private val resources = PhilologyResources(baseResources) - private val someCharSequence: CharSequence = "text" - private val someString: String = someCharSequence.toString() - private val repoCharSequence: CharSequence = "repo" - private val repoString: String = repoCharSequence.toString() - private val id = 0 - private val nameId = "nameId" + private val configuration: Configuration = createConfiguration() + private val baseResources: Resources = mock() + private val resourcesUtil = spy(ResourcesUtil(baseResources)) + private val philologyResources = PhilologyResources(resourcesUtil).also { + Mockito.reset(baseResources, resourcesUtil) + } + private val someCharSequence: CharSequence = randomString() + private val someString: String = someCharSequence.toString() + private val repoCharSequence: CharSequence = randomString() + private val repoString: String = repoCharSequence.toString() + private val id = randomInt() + private val formatArg = randomString() + private val nameId = randomString() @Before fun setup() { @@ -44,394 +57,1492 @@ class PhilologyResourcesTest { When calling baseResources.configuration doReturn configuration } - @Test - fun `Should throw an exception if the given id doesn't exist asking for a text`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getText(id) } `should throw` Resources.NotFoundException::class - } + @Test + fun `Should throw an exception if the given id doesn't exist asking for a text`() { + configureResourceGetIdException(baseResources, id) - @Test - fun `Should return a CharSequence asking for a text`() { - configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getText(id) `should be equal to` someCharSequence - } + invoking { philologyResources.getText(id) } `should throw` Resources.NotFoundException::class - @Test - fun `Should return a defaultCharSequence asking for a text with a default value`() { - val defaultCharSequence: CharSequence = "default char sequence" - configureResourceGetIdException(baseResources, id) - resources.getText(id, defaultCharSequence) `should be equal to` defaultCharSequence - } + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return a CharSequence asking for a text with a default value`() { - val defaultCharSequence: CharSequence = "default char sequence" - configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getText(id, defaultCharSequence) `should be equal to` someCharSequence - } + @Test + fun `Should return a CharSequence asking for a text`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) - @Test - fun `Should throw an exception if the given id doesn't exist asking for an String`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getString(id) } `should throw` Resources.NotFoundException::class - } + val result = philologyResources.getText(id) - @Test - fun `Should return a CharSequence asking for an String`() { - configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getString(id) `should be equal to` someString - } + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should throw an exception if the given id doesn't exist asking for a quantity text`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getQuantityText(id, 1) } `should throw` Resources.NotFoundException::class - } + @Test + fun `Should return a CharSequence from repository asking for a text`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, repoCharSequence)) - @Test - fun `Should return a CharSequence asking for a quantity text`() { - configureResourceQuantityString(baseResources, 1, "one") - configureResourceGetQuantityText(baseResources, id, nameId, 1, someCharSequence) - resources.getQuantityText(id, 1) `should be equal to` someCharSequence - } + val result = philologyResources.getText(id) - @Test - fun `Should throw an exception if the given id doesn't exist asking for an quantity string`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getQuantityString(id, 1) } `should throw` Resources.NotFoundException::class - } + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return a CharSequence asking for an quantity string`() { - configureResourceQuantityString(baseResources, 1, "one") - configureResourceGetQuantityText(baseResources, id, nameId, 1, someCharSequence) - resources.getQuantityString(id, 1) `should be equal to` someString - } + @Test + fun `Should return a CharSequence asking for a text with default value`() { + val defaultCharSequence = randomString() + configureResourceGetText(baseResources, id, nameId, someCharSequence) - @Test - fun `Should throw an exception if the given id doesn't exist asking for a string array`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getStringArray(id) } `should throw` Resources.NotFoundException::class - } + val result = philologyResources.getText(id, defaultCharSequence) - @Test - fun `Should return a CharSequence asking for a string array`() { - val textArray = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - resources.getStringArray(id) `should be equal to` textArray.map { it.toString() }.toTypedArray() - } + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id, defaultCharSequence) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should throw an exception if the given id doesn't exist asking for a text array`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getStringArray(id) } `should throw` Resources.NotFoundException::class - } + @Test + fun `Should return a CharSequence from repository asking for a text with default value`() { + val defaultCharSequence = randomString() + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, repoCharSequence)) - @Test - fun `Should return a CharSequence asking for a text array`() { - val textArray = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - resources.getTextArray(id) `should be equal to` textArray - } + val result = philologyResources.getText(id, defaultCharSequence) - @Test - fun `Should return a CharSequence from repository asking for a text`() { - configureResourceGetText(baseResources, id, nameId, someCharSequence) - configurePhilology(createRepository(nameId, null, repoCharSequence)) - resources.getText(id) `should be equal to` repoCharSequence - } + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id, defaultCharSequence) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return a CharSequence from repository asking for an String`() { - configureResourceGetText(baseResources, id, nameId, someCharSequence) - configurePhilology(createRepository(nameId, null, repoCharSequence)) - resources.getString(id) `should be equal to` repoString - } + @Test + fun `Should return a the default CharSequence asking for a text`() { + val defaultCharSequence: CharSequence = randomString() + configureResourceGetIdException(baseResources, id) - @Test - fun `Should return a CharSequence from repository asking for a quantity text`() { - configureResourceQuantityString(baseResources, 1, "one") - configureResourceGetQuantityText(baseResources, id, nameId, 1, someCharSequence) - configurePhilology(createRepository(nameId, "one", repoCharSequence)) - resources.getQuantityText(id, 1) `should be equal to` repoCharSequence - } + val result = philologyResources.getText(id, defaultCharSequence) - @Test - fun `Should return a CharSequence from repository asking for an quantity string`() { - configureResourceQuantityString(baseResources, 1, "one") - configureResourceGetQuantityText(baseResources, id, nameId, 1, someCharSequence) - configurePhilology(createRepository(nameId, "one", repoCharSequence)) - resources.getQuantityString(id, 1) `should be equal to` repoString - } + result `should be equal to` defaultCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id, defaultCharSequence) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return a CharSequence from repository asking for a string array`() { - val textArray: Array = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - configurePhilology(createRepository(nameId, textArray = textArray)) - resources.getStringArray(id) `should be equal to` textArray.map { it.toString() }.toTypedArray() - } + @Test + fun `Should throw an exception if the given id doesn't exist asking for an String`() { + configureResourceGetIdException(baseResources, id) - @Test - fun `Should return a CharSequence from repository asking for a text array`() { - val textArray: Array = arrayOf("first", "second") - configureResourceGetTextArray(baseResources, id, nameId, textArray) - configurePhilology(createRepository(nameId, textArray = textArray)) - resources.getTextArray(id) `should be equal to` textArray - } + invoking { philologyResources.getString(id) } `should throw` Resources.NotFoundException::class - @Test - fun `Should return an XmlResourceParser from base resources asking for an Animation`() { - val xmlResourceParser = mock() - When calling baseResources.getAnimation(id) doReturn xmlResourceParser - resources.getAnimation(id) `should be equal to` xmlResourceParser - } + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return a DisplayMetrics from base resources asking for a display metrics`() { - val displayMetrics = mock() - When calling baseResources.displayMetrics doReturn displayMetrics - resources.displayMetrics `should be equal to` displayMetrics - } + @Test + fun `Should return a CharSequence asking for an String`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) - @Test - fun `Should return a Drawable from base resources asking for a drawable for density`() { - val drawable = mock() - When calling baseResources.getDrawableForDensity(id, 2) doReturn drawable - resources.getDrawableForDensity(id, 2) `should be equal to` drawable - } + val result = philologyResources.getString(id) - @Test - fun `Should return a Drawable from base resources asking for a drawable for density on API 21+`() { - val drawable = mock() - val theme = mock() - When calling baseResources.getDrawableForDensity(id, 2, theme) doReturn drawable - resources.getDrawableForDensity(id, 2, theme) `should be equal to` drawable - } + result `should be equal to` someString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return Configuration from base resources asking for a configuration`() { - val configuration = mock() - When calling baseResources.configuration doReturn configuration - resources.configuration `should be equal to` configuration - } + @Test + fun `Should return a CharSequence from repository asking for an String`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, repoCharSequence)) - @Test - fun `Should return TypedArray from base resources asking for a attributes`() { - val attributes = mock() - val attributeSet = mock() - val attrs = IntArray(3) - When calling baseResources.obtainAttributes(attributeSet, attrs) doReturn attributes - resources.obtainAttributes(attributeSet, attrs) `should be equal to` attributes - } + val result = philologyResources.getString(id) - @Test - fun `Should return Int from base resources asking for a dimension pixel size`() { - When calling baseResources.getDimensionPixelSize(id) doReturn 15 - resources.getDimensionPixelSize(id) `should be equal to` 15 - } + result `should be equal to` repoString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return IntArray from base resources asking for a int array`() { - val intArray = IntArray(5) - When calling baseResources.getIntArray(id) doReturn intArray - resources.getIntArray(id) `should be equal to` intArray - } + @Test + fun `Should throw an exception if the given id doesn't exist asking for a formatted String`() { + configureResourceGetIdException(baseResources, id) - @Test - fun `Should call getValue method from base resources asking value by name`() { - val outValue = mock() - resources.getValue(id, outValue, true) - verify(baseResources).getValue(id, outValue, true) - } + invoking { philologyResources.getString(id, formatArg) } `should throw` Resources.NotFoundException::class - @Test - fun `Should call getValue method from base resources asking value by id`() { - val outValue = mock() - resources.getValue("id", outValue, true) - verify(baseResources).getValue("id", outValue, true) - } + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return String from base resources asking for a resource package name`() { - val packageName = "com.package.name" - When calling baseResources.getResourcePackageName(id) doReturn packageName - resources.getResourcePackageName(id) `should be equal to` packageName - } + @Test + fun `Should return a CharSequence asking for a formatted String`() { + configureResourceGetText(baseResources, id, nameId, "$someCharSequence%s") - @Test - fun `Should return AssetFileDescriptor from base resources on open raw resource`() { - val fileDescriptor = mock() - When calling baseResources.openRawResourceFd(id) doReturn fileDescriptor - resources.openRawResourceFd(id) `should be equal to` fileDescriptor - } + val result = philologyResources.getString(id, formatArg) - @Test - fun `Should return Float from base resources asking for a dimension`() { - val dimension = 15f - When calling baseResources.getDimension(id) doReturn dimension - resources.getDimension(id) `should be equal to` dimension - } + result `should be equal to` "$someString$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return ColorStateList from base resources asking for a color state list`() { - val colorStateList = mock() - When calling baseResources.getColorStateList(id) doReturn colorStateList - resources.getColorStateList(id) `should be equal to` colorStateList - } + @Test + fun `Should return a CharSequence from repository asking for a formatted String`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, "$repoCharSequence%s")) - @Test - fun `Should return ColorStateList from base resources asking for a color state list on API 23+`() { - val colorStateList = mock() - val theme = mock() - When calling baseResources.getColorStateList(id, theme) doReturn colorStateList - resources.getColorStateList(id, theme) `should be equal to` colorStateList - } + val result = philologyResources.getString(id, formatArg) - @Test - fun `Should return Boolean from base resources asking for a boolean`() { - When calling baseResources.getBoolean(id) doReturn true - resources.getBoolean(id) `should be equal to` true - } + result `should be equal to` "$repoString$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return Int from base resources asking for a identifier`() { - When calling baseResources.getIdentifier("name", "defType", "defPackage") doReturn 5 - resources.getIdentifier("name", "defType", "defPackage") `should be equal to` 5 - } + @Test + fun `Should throw an exception if the given id doesn't exist asking for a quantity text`() { + val quantity = randomInt() + configureResourceGetIdException(baseResources, id) - @Test - fun `Should return Int from base resources asking for a color`() { - When calling baseResources.getColor(id) doReturn 15 - resources.getColor(id) `should be equal to` 15 - } + invoking { philologyResources.getQuantityText(id, quantity) } `should throw` Resources.NotFoundException::class - @Test - fun `Should return Int from base resources asking for a color on API 23+`() { - val theme = mock() - When calling baseResources.getColor(id, theme) doReturn 15 - resources.getColor(id, theme) `should be equal to` 15 - } + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return InputStream from base resources on open raw resource`() { - val inputStream = mock() - When calling baseResources.openRawResource(id) doReturn inputStream - resources.openRawResource(id) `should be equal to` inputStream - } + @Test + fun `Should return a CharSequence asking for a quantity text`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - @Test - fun `Should return InputStream from base resources on open raw resource with typed value param`() { - val inputStream = mock() - val typedValue = mock() - When calling baseResources.openRawResource(id, typedValue) doReturn inputStream - resources.openRawResource(id, typedValue) `should be equal to` inputStream - } + val result = philologyResources.getQuantityText(id, quantity) - @Test - fun `Should return Movie from base resources asking for a movie`() { - val movie = mock() - When calling baseResources.getMovie(id) doReturn movie - resources.getMovie(id) `should be equal to` movie - } + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + Verify on resourcesUtil that resourcesUtil.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return Integer from base resources asking for a integer`() { - When calling baseResources.getInteger(id) doReturn 7 - resources.getInteger(id) `should be equal to` 7 - } + @Test + fun `Should return a CharSequence asking for a quantity text from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, repoCharSequence)) - @Test - fun `Should call parseBundleExtras method from base resources on parse bundle extras`() { - val parser = mock() - val bundle = Bundle() - resources.parseBundleExtras(parser, bundle) - verify(baseResources).parseBundleExtras(parser, bundle) - } + val result = philologyResources.getQuantityText(id, quantity) - @Test - fun `Should return Drawable from base resources asking for a drawable`() { - val drawable = mock() - When calling baseResources.getDrawable(id) doReturn drawable - resources.getDrawable(id) `should be equal to` drawable - } + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on resourcesUtil that resourcesUtil.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return Drawable from base resources asking for a drawable on API 21+`() { - val drawable = mock() - val theme = mock() - When calling baseResources.getDrawable(id, theme) doReturn drawable - resources.getDrawable(id, theme) `should be equal to` drawable - } + @Test + fun `Should throw an exception if the given id doesn't exist asking for an quantity String`() { + val quantity = randomInt() + configureResourceGetIdException(baseResources, id) - @Test - fun `Should return String from base resources asking for a resource type name`() { - val typeName = "typeName" - When calling baseResources.getResourceTypeName(id) doReturn typeName - resources.getResourceTypeName(id) `should be equal to` typeName - } + invoking { philologyResources.getQuantityString(id, quantity) } `should throw` Resources.NotFoundException::class - @Test - fun `Should return XmlResourceParser from base resources asking for a layout`() { - val xmlParser = mock() - When calling baseResources.getLayout(id) doReturn xmlParser - resources.getLayout(id) `should be equal to` xmlParser - } + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return Typeface from base resources asking for a font`() { - val typeface = mock() - When calling baseResources.getFont(id) doReturn typeface - resources.getFont(id) `should be equal to` typeface - } + @Test + fun `Should return a CharSequence asking for an quantity String`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) - @Test - fun `Should return XmlResourceParser from base resources asking for a xml`() { - val xmlParser = mock() - When calling baseResources.getXml(id) doReturn xmlParser - resources.getXml(id) `should be equal to` xmlParser - } + val result = philologyResources.getQuantityString(id, quantity) - @Test - fun `Should return String from base resources asking for a resource name`() { - val resourceName = "resourceName" - When calling baseResources.getResourceName(id) doReturn resourceName - resources.getResourceName(id) `should be equal to` resourceName - } + result `should be equal to` someString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should call parseBundleExtra method from base resources on parse bundle extra`() { - val tagName = "tagName" - val attrs = mock() - val bundle = Bundle() - resources.parseBundleExtra(tagName, attrs, bundle) - verify(baseResources).parseBundleExtra(tagName, attrs, bundle) - } + @Test + fun `Should return a CharSequence asking for an quantity String from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, repoCharSequence)) - @Test - fun `Should return Int from base resources asking for a dimension pixel offset`() { - When calling baseResources.getDimensionPixelOffset(id) doReturn 15 - resources.getDimensionPixelOffset(id) `should be equal to` 15 - } + val result = philologyResources.getQuantityString(id, quantity) - @Test - fun `Should call getValueForDensity method from base resources on get value for density`() { - val outValue = mock() - resources.getValueForDensity(id, 2, outValue, true) - verify(baseResources).getValueForDensity(id, 2, outValue, true) - } + result `should be equal to` repoString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } - @Test - fun `Should return String from base resources asking for a resource entry name`() { - val entryName = "entryName" - When calling baseResources.getResourceEntryName(id) doReturn entryName - resources.getResourceEntryName(id) `should be equal to` entryName - } + @Test + fun `Should throw an exception if id doesn't exist asking for a formatted quantity String`() { + configureResourceGetIdException(baseResources, id) + val quantity = randomInt() - @Test - fun `Should return Float from base resources asking for a fraction`() { - val fraction = 132f - When calling baseResources.getFraction(id, 2, 5) doReturn fraction - resources.getFraction(id, 2, 5) `should be equal to` fraction - } + invoking { philologyResources.getQuantityString(id, quantity, formatArg) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a formatted quantity String`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, "$someCharSequence%s") + + val result = philologyResources.getQuantityString(id, quantity, formatArg) + + result `should be equal to` someString + formatArg + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a formatted quantity text from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, "$repoCharSequence%s")) + + val result = philologyResources.getQuantityString(id, quantity, formatArg) + + result `should be equal to` "$repoCharSequence$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for text array`() { + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getTextArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getTextArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings asking for a text array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + configureResourceGetTextArray(baseResources, id, nameId, textArray) + + val result = philologyResources.getTextArray(id) + + result `should be equal to` textArray + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getTextArray(id) was called + Verify on resourcesUtil that resourcesUtil.getTextArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings from repository asking for a text array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + configureResourceGetTextArray(baseResources, id, nameId, arrayOf(randomString(), randomString())) + configurePhilology(createRepository(nameId, textArray = textArray)) + + val result = philologyResources.getTextArray(id) + + result `should be equal to` textArray + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getTextArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for a string array`() { + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getStringArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getStringArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings asking for a string array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + val expectedResult = textArray.map { it.toString() }.toTypedArray() + configureResourceGetTextArray(baseResources, id, nameId, textArray) + + val result = philologyResources.getStringArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getTextArray(id) was called + Verify on resourcesUtil that resourcesUtil.getStringArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings from repository asking for a string array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + val expectedResult = textArray.map { it.toString() }.toTypedArray() + configureResourceGetTextArray(baseResources, id, nameId, arrayOf(randomString(), randomString())) + configurePhilology(createRepository(nameId, textArray = textArray)) + + val result = philologyResources.getStringArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getStringArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getAnimation`() { + val id = randomInt() + When calling baseResources.getAnimation(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getAnimation(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getAnimation(id) was called + Verify on resourcesUtil that resourcesUtil.getAnimation(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return animation calling getAnimation`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getAnimation(id) doReturn expectedResult + + val result = philologyResources.getAnimation(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getAnimation(id) was called + Verify on resourcesUtil that resourcesUtil.getAnimation(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return displayMetrics calling getDisplayMetrics`() { + val expectedResult: DisplayMetrics = mock() + When calling baseResources.displayMetrics doReturn expectedResult + + val result = philologyResources.getDisplayMetrics() + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.displayMetrics was called + Verify on resourcesUtil that resourcesUtil.getDisplayMetrics() was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + When calling baseResources.getDrawableForDensity(id, density) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.getDrawableForDensity(id, density) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawableForDensity(id, density) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawableForDensity(id, density) doReturn expectedResult + + val result = philologyResources.getDrawableForDensity(id, density) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawableForDensity(id, density) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getDrawableForDensity(id, density, theme) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.getDrawableForDensity(id, density, theme) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDrawableForDensity(id, density, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawableForDensity(id, density, theme) doReturn expectedResult + + val result = philologyResources.getDrawableForDensity(id, density, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawableForDensity(id, density, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return configuration calling getConfiguration`() { + val result = philologyResources.getConfiguration() + + result `should be equal to` configuration + Verify on baseResources that baseResources.configuration was called + Verify on resourcesUtil that resourcesUtil.getConfiguration() was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception calling obtainAttributes`() { + val set: AttributeSet = mock() + val attrs: IntArray = intArrayOf(randomInt()) + When calling baseResources.obtainAttributes(set, attrs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.obtainAttributes(set, attrs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.obtainAttributes(set, attrs) was called + Verify on resourcesUtil that resourcesUtil.obtainAttributes(set, attrs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return animation calling obtainAttributes`() { + val set: AttributeSet = mock() + val attrs: IntArray = intArrayOf(randomInt()) + val expectedResult: TypedArray = mock() + When calling baseResources.obtainAttributes(set, attrs) doReturn expectedResult + + val result = philologyResources.obtainAttributes(set, attrs) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.obtainAttributes(set, attrs) was called + Verify on resourcesUtil that resourcesUtil.obtainAttributes(set, attrs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling obtainTypedArray`() { + val id = randomInt() + When calling baseResources.obtainTypedArray(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.obtainTypedArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.obtainTypedArray(id) was called + Verify on resourcesUtil that resourcesUtil.obtainTypedArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return TypedArray calling obtainTypedArray`() { + val id = randomInt() + val expectedResult: TypedArray = mock() + When calling baseResources.obtainTypedArray(id) doReturn expectedResult + + val result = resourcesUtil.obtainTypedArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.obtainTypedArray(id) was called + Verify on resourcesUtil that resourcesUtil.obtainTypedArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimensionPixelSize`() { + val id = randomInt() + When calling baseResources.getDimensionPixelSize(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDimensionPixelSize(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimensionPixelSize(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelSize(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return dimension calling getDimensionPixelSize`() { + val id = randomInt() + val expectedResult: Int = randomInt() + When calling baseResources.getDimensionPixelSize(id) doReturn expectedResult + + val result = philologyResources.getDimensionPixelSize(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimensionPixelSize(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelSize(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getIntArray`() { + val id = randomInt() + When calling baseResources.getIntArray(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getIntArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getIntArray(id) was called + Verify on resourcesUtil that resourcesUtil.getIntArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return intArray calling getIntArray`() { + val id = randomInt() + val expectedResult: IntArray = intArrayOf(randomInt(), randomInt(), randomInt()) + When calling baseResources.getIntArray(id) doReturn expectedResult + + val result = philologyResources.getIntArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getIntArray(id) was called + Verify on resourcesUtil that resourcesUtil.getIntArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getValue`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValue(id, typedValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getValue(id, typedValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValue(id, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(id, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return value calling getValue`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + philologyResources.getValue(id, typedValue, resolveRefs) + + Verify on baseResources that baseResources.getValue(id, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(id, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given name doesn't exist calling getValue`() { + val name = randomString() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValue(name, typedValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getValue(name, typedValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValue(name, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(name, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return value calling getValue`() { + val name = randomString() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + philologyResources.getValue(name, typedValue, resolveRefs) + + Verify on baseResources that baseResources.getValue(name, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(name, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourcePackageName`() { + val id = randomInt() + When calling baseResources.getResourcePackageName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourcePackageName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourcePackageName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourcePackageName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return package calling getResourcePackageName`() { + val id = randomInt() + val expectedResult: String = randomString() + When calling baseResources.getResourcePackageName(id) doReturn expectedResult + + val result = philologyResources.getResourcePackageName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourcePackageName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourcePackageName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResourceFd`() { + val id = randomInt() + When calling baseResources.openRawResourceFd(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.openRawResourceFd(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.openRawResourceFd(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResourceFd(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return assetFileDescriptor calling openRawResourceFd`() { + val id = randomInt() + val expectedResult: AssetFileDescriptor = mock() + When calling baseResources.openRawResourceFd(id) doReturn expectedResult + + val result = philologyResources.openRawResourceFd(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResourceFd(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResourceFd(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimension`() { + val id = randomInt() + When calling baseResources.getDimension(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDimension(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimension(id) was called + Verify on resourcesUtil that resourcesUtil.getDimension(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return dimension calling getDimension`() { + val id = randomInt() + val expectedResult = randomFloat() + When calling baseResources.getDimension(id) doReturn expectedResult + + val result = philologyResources.getDimension(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimension(id) was called + Verify on resourcesUtil that resourcesUtil.getDimension(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColorStateList`() { + val id = randomInt() + When calling baseResources.getColorStateList(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getColorStateList(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColorStateList(id) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return colorStateList calling getColorStateList`() { + val id = randomInt() + val expectedResult: ColorStateList = mock() + When calling baseResources.getColorStateList(id) doReturn expectedResult + + val result = philologyResources.getColorStateList(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColorStateList(id) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColorStateList`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getColorStateList(id, theme) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.getColorStateList(id, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getColorStateList(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return colorStateList calling getColorStateList`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: ColorStateList = mock() + When calling baseResources.getColorStateList(id, theme) doReturn expectedResult + + val result = philologyResources.getColorStateList(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColorStateList(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getBoolean`() { + val id = randomInt() + When calling baseResources.getBoolean(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getBoolean(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getBoolean(id) was called + Verify on resourcesUtil that resourcesUtil.getBoolean(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return boolean calling getBoolean`() { + val id = randomInt() + val expectedResult = randomBoolean() + When calling baseResources.getBoolean(id) doReturn expectedResult + + val result = philologyResources.getBoolean(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getBoolean(id) was called + Verify on resourcesUtil that resourcesUtil.getBoolean(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getIdentifier`() { + val name = randomString() + val defType = randomString() + val defPackage = randomString() + When calling baseResources.getIdentifier(name, defType, defPackage) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getIdentifier(name, defType, defPackage) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getIdentifier(name, defType, defPackage) was called + Verify on resourcesUtil that resourcesUtil.getIdentifier(name, defType, defPackage) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return integer calling getIdentifier`() { + val name = randomString() + val defType = randomString() + val defPackage = randomString() + val expectedResult = randomInt() + When calling baseResources.getIdentifier(name, defType, defPackage) doReturn expectedResult + + val result = philologyResources.getIdentifier(name, defType, defPackage) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getIdentifier(name, defType, defPackage) was called + Verify on resourcesUtil that resourcesUtil.getIdentifier(name, defType, defPackage) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColor`() { + val id = randomInt() + When calling baseResources.getColor(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getColor(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColor(id) was called + Verify on resourcesUtil that resourcesUtil.getColor(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return color calling getColor`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getColor(id) doReturn expectedResult + + val result = philologyResources.getColor(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColor(id) was called + Verify on resourcesUtil that resourcesUtil.getColor(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColor`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getColor(id, theme) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getColor(id, theme) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColor(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColor(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return color calling getColor`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult = randomInt() + When calling baseResources.getColor(id, theme) doReturn expectedResult + + val result = philologyResources.getColor(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColor(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColor(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should call to updateConfiguration`() { + val newConf: Configuration = mock() + val newMetrics: DisplayMetrics = mock() + + philologyResources.updateConfiguration(newConf, newMetrics) + + Verify on baseResources that baseResources.updateConfiguration(newConf, newMetrics) was called + Verify on resourcesUtil that resourcesUtil.updateConfiguration(newConf, newMetrics) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResource`() { + val id = randomInt() + When calling baseResources.openRawResource(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.openRawResource(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.openRawResource(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return inputStream calling openRawResource`() { + val id = randomInt() + val expectedResult: InputStream = mock() + When calling baseResources.openRawResource(id) doReturn expectedResult + + val result = philologyResources.openRawResource(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResource(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResource`() { + val id = randomInt() + val typedValue: TypedValue = mock() + When calling baseResources.openRawResource(id, typedValue) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.openRawResource(id, typedValue) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.openRawResource(id, typedValue) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id, typedValue) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return inputStream calling openRawResource`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val expectedResult: InputStream = mock() + When calling baseResources.openRawResource(id, typedValue) doReturn expectedResult + + val result = philologyResources.openRawResource(id, typedValue) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResource(id, typedValue) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id, typedValue) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getMovie`() { + val id = randomInt() + When calling baseResources.getMovie(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getMovie(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getMovie(id) was called + Verify on resourcesUtil that resourcesUtil.getMovie(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Movie calling getMovie`() { + val id = randomInt() + val expectedResult: Movie = mock() + When calling baseResources.getMovie(id) doReturn expectedResult + + val result = philologyResources.getMovie(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getMovie(id) was called + Verify on resourcesUtil that resourcesUtil.getMovie(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getInteger`() { + val id = randomInt() + When calling baseResources.getInteger(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getInteger(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getInteger(id) was called + Verify on resourcesUtil that resourcesUtil.getInteger(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Integer calling getInteger`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getInteger(id) doReturn expectedResult + + val result = philologyResources.getInteger(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getInteger(id) was called + Verify on resourcesUtil that resourcesUtil.getInteger(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an XmlPullParserException if the given id doesn't exist calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtras(parser, outBundle) doThrow XmlPullParserException::class + + invoking { philologyResources.parseBundleExtras(parser, outBundle) } `should throw` XmlPullParserException::class + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an IOException if the given id doesn't exist calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtras(parser, outBundle) doThrow IOException::class + + invoking { philologyResources.parseBundleExtras(parser, outBundle) } `should throw` IOException::class + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Integer calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + + philologyResources.parseBundleExtras(parser, outBundle) + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawable`() { + val id = randomInt() + When calling baseResources.getDrawable(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDrawable(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDrawable(id) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawable`() { + val id = randomInt() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawable(id) doReturn expectedResult + + val result = philologyResources.getDrawable(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawable(id) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawable`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getDrawable(id, theme) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDrawable(id, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawable(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawable`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawable(id, theme) doReturn expectedResult + + val result = philologyResources.getDrawable(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawable(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceTypeName`() { + val id = randomInt() + When calling baseResources.getResourceTypeName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourceTypeName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceTypeName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceTypeName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling getResourceTypeName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceTypeName(id) doReturn expectedResult + + val result = philologyResources.getResourceTypeName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceTypeName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceTypeName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getLayout`() { + val id = randomInt() + When calling baseResources.getLayout(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getLayout(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getLayout(id) was called + Verify on resourcesUtil that resourcesUtil.getLayout(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return layout calling getLayout`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getLayout(id) doReturn expectedResult + + val result = philologyResources.getLayout(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getLayout(id) was called + Verify on resourcesUtil that resourcesUtil.getLayout(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getFont`() { + val id = randomInt() + When calling baseResources.getFont(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getFont(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getFont(id) was called + Verify on resourcesUtil that resourcesUtil.getFont(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return typeFace calling getFont`() { + val id = randomInt() + val expectedResult: Typeface = mock() + When calling baseResources.getFont(id) doReturn expectedResult + + val result = philologyResources.getFont(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getFont(id) was called + Verify on resourcesUtil that resourcesUtil.getFont(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getXml`() { + val id = randomInt() + When calling baseResources.getXml(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getXml(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getXml(id) was called + Verify on resourcesUtil that resourcesUtil.getXml(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return xml calling getXml`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getXml(id) doReturn expectedResult + + val result = philologyResources.getXml(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getXml(id) was called + Verify on resourcesUtil that resourcesUtil.getXml(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceName`() { + val id = randomInt() + When calling baseResources.getResourceName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourceName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling getResourceName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceName(id) doReturn expectedResult + + val result = philologyResources.getResourceName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling parseBundleExtra`() { + val tagName: String = randomString() + val attrs: AttributeSet = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtra(tagName, attrs, outBundle) doThrow XmlPullParserException::class + + invoking { philologyResources.parseBundleExtra(tagName, attrs, outBundle) } `should throw` XmlPullParserException::class + + Verify on baseResources that baseResources.parseBundleExtra(tagName, attrs, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling parseBundleExtra`() { + val tagName: String = randomString() + val attrs: AttributeSet = mock() + val outBundle: Bundle = mock() + + philologyResources.parseBundleExtra(tagName, attrs, outBundle) + + Verify on baseResources that baseResources.parseBundleExtra(tagName, attrs, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimensionPixelOffset`() { + val id = randomInt() + When calling baseResources.getDimensionPixelOffset(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDimensionPixelOffset(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimensionPixelOffset(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelOffset(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Integer calling getDimensionPixelOffset`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getDimensionPixelOffset(id) doReturn expectedResult + + val result = philologyResources.getDimensionPixelOffset(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimensionPixelOffset(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelOffset(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getValueForDensity`() { + val id = randomInt() + val density = randomInt() + val outValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValueForDensity(id, density, outValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getValueForDensity(id, density, outValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValueForDensity(id, density, outValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getValueForDensity`() { + val id = randomInt() + val density = randomInt() + val outValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + philologyResources.getValueForDensity(id, density, outValue, resolveRefs) + + Verify on baseResources that baseResources.getValueForDensity(id, density, outValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceEntryName`() { + val id = randomInt() + When calling baseResources.getResourceEntryName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourceEntryName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling getResourceEntryName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceEntryName(id) doReturn expectedResult + + val result = philologyResources.getResourceEntryName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getFraction`() { + val id = randomInt() + val base = randomInt() + val pbase = randomInt() + When calling baseResources.getFraction(id, base, pbase) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getFraction(id, base, pbase) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getFraction(id, base, pbase) was called + Verify on resourcesUtil that resourcesUtil.getFraction(id, base, pbase) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return dimension calling getFraction`() { + val id = randomInt() + val base = randomInt() + val pbase = randomInt() + val expectedResult = randomFloat() + When calling baseResources.getFraction(id, base, pbase) doReturn expectedResult + + val result = philologyResources.getFraction(id, base, pbase) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getFraction(id, base, pbase) was called + Verify on resourcesUtil that resourcesUtil.getFraction(id, base, pbase) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } } From dbe5d7ef3479d789436e81ef57b934e3c94f9676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jc=20Mi=C3=B1arro?= Date: Sat, 1 Feb 2020 10:31:28 +0100 Subject: [PATCH 5/5] Refactor PhilologyVectorEnabledTintResources --- .../philology/PhilologyContextWrapper.kt | 6 +- .../PhilologyVectorEnabledTintResources.kt | 213 ++- ...PhilologyVectorEnabledTintResourcesTest.kt | 1518 ++++++++++++++++- 3 files changed, 1707 insertions(+), 30 deletions(-) diff --git a/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt b/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt index d647d88..faf625c 100644 --- a/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt +++ b/philology/src/main/java/com/jcminarro/philology/PhilologyContextWrapper.kt @@ -10,11 +10,11 @@ import androidx.appcompat.widget.VectorEnabledTintResources @SuppressLint("RestrictedApi") internal class PhilologyContextWrapper(base: Context) : ContextWrapper(base) { private val res: Resources by lazy { - val baseResources = super.getResources() + val resourcesUtil = ResourcesUtil(super.getResources()) if (VectorEnabledTintResources.shouldBeUsed()) { - PhilologyVectorEnabledTintResources(this, baseResources) + PhilologyVectorEnabledTintResources(this, resourcesUtil) } else { - PhilologyResources(ResourcesUtil(baseResources)) + PhilologyResources(resourcesUtil) } } diff --git a/philology/src/main/java/com/jcminarro/philology/PhilologyVectorEnabledTintResources.kt b/philology/src/main/java/com/jcminarro/philology/PhilologyVectorEnabledTintResources.kt index 7309885..12d00ef 100644 --- a/philology/src/main/java/com/jcminarro/philology/PhilologyVectorEnabledTintResources.kt +++ b/philology/src/main/java/com/jcminarro/philology/PhilologyVectorEnabledTintResources.kt @@ -1,16 +1,217 @@ package com.jcminarro.philology import android.annotation.SuppressLint +import android.annotation.TargetApi import android.content.Context -import android.content.res.Resources +import android.content.res.AssetFileDescriptor +import android.content.res.ColorStateList +import android.content.res.Configuration +import android.content.res.TypedArray +import android.content.res.XmlResourceParser +import android.graphics.Movie +import android.graphics.Typeface +import android.graphics.drawable.Drawable +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.util.AttributeSet +import android.util.DisplayMetrics +import android.util.TypedValue +import androidx.annotation.AnimRes +import androidx.annotation.AnimatorRes +import androidx.annotation.AnyRes +import androidx.annotation.ArrayRes +import androidx.annotation.BoolRes +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.annotation.DimenRes +import androidx.annotation.DrawableRes +import androidx.annotation.FontRes +import androidx.annotation.FractionRes +import androidx.annotation.IntegerRes +import androidx.annotation.LayoutRes +import androidx.annotation.PluralsRes +import androidx.annotation.RawRes +import androidx.annotation.RequiresApi +import androidx.annotation.StringRes +import androidx.annotation.StyleableRes +import androidx.annotation.XmlRes import androidx.appcompat.widget.VectorEnabledTintResources +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException +import java.io.InputStream @SuppressWarnings("RestrictedApi") @SuppressLint("RestrictedApi") -internal class PhilologyVectorEnabledTintResources(baseContext: Context, baseResources: Resources) - : VectorEnabledTintResources(baseContext, baseResources) { - private val resourcesUtil = ResourcesUtil(baseResources) +internal class PhilologyVectorEnabledTintResources(baseContext: Context, + private val resourcesUtil: ResourcesUtil +) : VectorEnabledTintResources(baseContext, resourcesUtil.baseResources) { - override fun getText(id: Int): CharSequence = resourcesUtil.getText(id) - override fun getString(id: Int): String = resourcesUtil.getString(id) + @Throws(NotFoundException::class) + override fun getText(@StringRes id: Int): CharSequence = resourcesUtil.getText(id) + + override fun getText(@StringRes id: Int, def: CharSequence): CharSequence = resourcesUtil.getText(id, def) + + @Throws(NotFoundException::class) + override fun getString(@StringRes id: Int): String = resourcesUtil.getString(id) + + @Throws(NotFoundException::class) + override fun getString(@StringRes id: Int, vararg formatArgs: Any?): String = + resourcesUtil.getString(id, *formatArgs) + + @Throws(NotFoundException::class) + override fun getQuantityText(@PluralsRes id: Int, quantity: Int): CharSequence = + resourcesUtil.getQuantityText(id, quantity) + + @Throws(NotFoundException::class) + override fun getQuantityString(@PluralsRes id: Int, quantity: Int): String = + resourcesUtil.getQuantityString(id, quantity) + + @Throws(NotFoundException::class) + override fun getQuantityString(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any?): String = + resourcesUtil.getQuantityString(id, quantity, *formatArgs) + + @Throws(NotFoundException::class) + override fun getTextArray(@ArrayRes id: Int): Array = resourcesUtil.getTextArray(id) + + @Throws(NotFoundException::class) + override fun getStringArray(@ArrayRes id: Int): Array = resourcesUtil.getStringArray(id) + + @Throws(NotFoundException::class) + override fun getAnimation(@AnimatorRes @AnimRes id: Int): XmlResourceParser = resourcesUtil.getAnimation(id) + + override fun getDisplayMetrics(): DisplayMetrics = resourcesUtil.getDisplayMetrics() + + @Throws(NotFoundException::class) + override fun getDrawableForDensity(@DrawableRes id: Int, density: Int): Drawable? = + resourcesUtil.getDrawableForDensity(id, density) + + @Throws(NotFoundException::class) + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + override fun getDrawableForDensity(@DrawableRes id: Int, density: Int, theme: Theme?): Drawable? = + resourcesUtil.getDrawableForDensity(id, density, theme) + + override fun getConfiguration(): Configuration = resourcesUtil.getConfiguration() + + override fun obtainAttributes(set: AttributeSet?, @StyleableRes attrs: IntArray?): TypedArray = + resourcesUtil.obtainAttributes(set, attrs) + + @Throws(NotFoundException::class) + override fun obtainTypedArray(@ArrayRes id: Int): TypedArray = resourcesUtil.obtainTypedArray(id) + + @Throws(NotFoundException::class) + override fun getDimensionPixelSize(@DimenRes id: Int): Int = resourcesUtil.getDimensionPixelSize(id) + + @Throws(NotFoundException::class) + override fun getIntArray(@ArrayRes id: Int): IntArray = resourcesUtil.getIntArray(id) + + @Throws(NotFoundException::class) + override fun getValue(@AnyRes id: Int, outValue: TypedValue?, resolveRefs: Boolean) { + resourcesUtil.getValue(id, outValue, resolveRefs) + } + + @Throws(NotFoundException::class) + override fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean) { + resourcesUtil.getValue(name, outValue, resolveRefs) + } + + @Throws(NotFoundException::class) + override fun getResourcePackageName(@AnyRes resid: Int): String = + resourcesUtil.getResourcePackageName(resid) + + @Throws(NotFoundException::class) + override fun openRawResourceFd(@RawRes id: Int): AssetFileDescriptor = + resourcesUtil.openRawResourceFd(id) + + @Throws(NotFoundException::class) + override fun getDimension(@DimenRes id: Int): Float = resourcesUtil.getDimension(id) + + @Throws(NotFoundException::class) + override fun getColorStateList(@ColorRes id: Int): ColorStateList = resourcesUtil.getColorStateList(id) + + @TargetApi(Build.VERSION_CODES.M) + override fun getColorStateList(@ColorRes id: Int, theme: Theme?): ColorStateList = + resourcesUtil.getColorStateList(id, theme) + + @Throws(NotFoundException::class) + override fun getBoolean(@BoolRes id: Int): Boolean = resourcesUtil.getBoolean(id) + + override fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int = + resourcesUtil.getIdentifier(name, defType, defPackage) + + @ColorInt + @Throws(NotFoundException::class) + override fun getColor(@ColorRes id: Int): Int = resourcesUtil.getColor(id) + + @TargetApi(Build.VERSION_CODES.M) + @ColorInt + @Throws(NotFoundException::class) + override fun getColor(@ColorRes id: Int, theme: Theme?): Int = resourcesUtil.getColor(id, theme) + + override fun updateConfiguration(config: Configuration?, metrics: DisplayMetrics?) { + Handler().post { resourcesUtil.updateConfiguration(config, metrics) } + } + + @Throws(NotFoundException::class) + override fun openRawResource(@RawRes id: Int): InputStream = resourcesUtil.openRawResource(id) + + @Throws(NotFoundException::class) + override fun openRawResource(@RawRes id: Int, value: TypedValue?): InputStream = + resourcesUtil.openRawResource(id, value) + + @Throws(NotFoundException::class) + override fun getMovie(@RawRes id: Int): Movie = resourcesUtil.getMovie(id) + + @Throws(NotFoundException::class) + override fun getInteger(@IntegerRes id: Int): Int = resourcesUtil.getInteger(id) + + @Throws(XmlPullParserException::class, IOException::class) + override fun parseBundleExtras(parser: XmlResourceParser?, outBundle: Bundle?) { + this.resourcesUtil.parseBundleExtras(parser, outBundle) + } + + @Throws(NotFoundException::class) + override fun getDrawable(@DrawableRes id: Int): Drawable = resourcesUtil.getDrawable(id) + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Throws(NotFoundException::class) + override fun getDrawable(@DrawableRes id: Int, theme: Theme?): Drawable = + resourcesUtil.getDrawable(id, theme) + + @Throws(NotFoundException::class) + override fun getResourceTypeName(@AnyRes resid: Int): String = resourcesUtil.getResourceTypeName(resid) + + @Throws(NotFoundException::class) + override fun getLayout(@LayoutRes id: Int): XmlResourceParser = resourcesUtil.getLayout(id) + + @RequiresApi(Build.VERSION_CODES.O) + @SuppressLint("NewApi") + @Throws(NotFoundException::class) + override fun getFont(@FontRes id: Int): Typeface = resourcesUtil.getFont(id) + + @Throws(NotFoundException::class) + override fun getXml(@XmlRes id: Int): XmlResourceParser = resourcesUtil.getXml(id) + + @Throws(NotFoundException::class) + override fun getResourceName(@AnyRes resid: Int): String = resourcesUtil.getResourceName(resid) + + @Throws(XmlPullParserException::class) + override fun parseBundleExtra(tagName: String?, attrs: AttributeSet?, outBundle: Bundle?) { + resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) + } + + @Throws(NotFoundException::class) + override fun getDimensionPixelOffset(@DimenRes id: Int): Int = resourcesUtil.getDimensionPixelOffset(id) + + @Throws(NotFoundException::class) + override fun getValueForDensity(@AnyRes id: Int, density: Int, outValue: TypedValue?, resolveRefs: Boolean) { + resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) + } + + @Throws(NotFoundException::class) + override fun getResourceEntryName(@AnyRes resid: Int): String = resourcesUtil.getResourceEntryName(resid) + + @Throws(NotFoundException::class) + override fun getFraction(@FractionRes id: Int, base: Int, pbase: Int): Float = + resourcesUtil.getFraction(id, base, pbase) } \ No newline at end of file diff --git a/philology/src/test/java/com/jcminarro/philology/PhilologyVectorEnabledTintResourcesTest.kt b/philology/src/test/java/com/jcminarro/philology/PhilologyVectorEnabledTintResourcesTest.kt index c08f2cc..74b9120 100644 --- a/philology/src/test/java/com/jcminarro/philology/PhilologyVectorEnabledTintResourcesTest.kt +++ b/philology/src/test/java/com/jcminarro/philology/PhilologyVectorEnabledTintResourcesTest.kt @@ -1,30 +1,55 @@ package com.jcminarro.philology -import android.content.Context +import android.content.res.AssetFileDescriptor +import android.content.res.ColorStateList import android.content.res.Configuration import android.content.res.Resources +import android.content.res.TypedArray +import android.content.res.XmlResourceParser +import android.graphics.Movie +import android.graphics.Typeface +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.util.AttributeSet +import android.util.DisplayMetrics +import android.util.TypedValue import com.nhaarman.mockito_kotlin.doReturn +import com.nhaarman.mockito_kotlin.doThrow +import com.nhaarman.mockito_kotlin.spy +import org.amshove.kluent.Verify import org.amshove.kluent.When +import org.amshove.kluent.`Verify no further interactions` import org.amshove.kluent.`should be equal to` import org.amshove.kluent.`should throw` +import org.amshove.kluent.called import org.amshove.kluent.calling import org.amshove.kluent.invoking import org.amshove.kluent.mock +import org.amshove.kluent.on +import org.amshove.kluent.that +import org.amshove.kluent.was import org.junit.Before import org.junit.Test +import org.mockito.Mockito +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException +import java.io.InputStream class PhilologyVectorEnabledTintResourcesTest { - private val baseResources: Resources = mock() - private val baseContext: Context = mock() private val configuration: Configuration = createConfiguration() - private val resources = PhilologyVectorEnabledTintResources(baseContext, baseResources) - private val someCharSequence: CharSequence = "text" + private val baseResources: Resources = mock() + private val resourcesUtil = spy(ResourcesUtil(baseResources)) + private val philologyResources = PhilologyVectorEnabledTintResources(mock(), resourcesUtil).also { + Mockito.reset(baseResources, resourcesUtil) + } + private val someCharSequence: CharSequence = randomString() private val someString: String = someCharSequence.toString() - private val repoCharSequence: CharSequence = "repo" + private val repoCharSequence: CharSequence = randomString() private val repoString: String = repoCharSequence.toString() - private val id = 0 - private val nameId = "nameId" + private val id = randomInt() + private val formatArg = randomString() + private val nameId = randomString() @Before fun setup() { @@ -33,40 +58,1491 @@ class PhilologyVectorEnabledTintResourcesTest { } @Test - fun `Should throw an exception if the given id doesn't exit asking for a text`() { + fun `Should throw an exception if the given id doesn't exist asking for a text`() { configureResourceGetIdException(baseResources, id) - invoking { resources.getText(id) } `should throw` Resources.NotFoundException::class + + invoking { philologyResources.getText(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil } @Test - fun `Should return a CharSecuence asking for a text`() { + fun `Should return a CharSequence asking for a text`() { configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getText(id) `should be equal to` someCharSequence + + val result = philologyResources.getText(id) + + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil } @Test - fun `Should throw an exception if the given id doesn't exit asking for an String`() { - configureResourceGetIdException(baseResources, id) - invoking { resources.getString(id) } `should throw` Resources.NotFoundException::class + fun `Should return a CharSequence from repository asking for a text`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, repoCharSequence)) + + val result = philologyResources.getText(id) + + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil } @Test - fun `Should return a CharSecuence asking for an String`() { + fun `Should return a CharSequence asking for a text with default value`() { + val defaultCharSequence = randomString() configureResourceGetText(baseResources, id, nameId, someCharSequence) - resources.getString(id) `should be equal to` someString + + val result = philologyResources.getText(id, defaultCharSequence) + + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id, defaultCharSequence) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil } @Test - fun `Should return a CharSecuence from repository asking for a text`() { + fun `Should return a CharSequence from repository asking for a text with default value`() { + val defaultCharSequence = randomString() configureResourceGetText(baseResources, id, nameId, someCharSequence) configurePhilology(createRepository(nameId, null, repoCharSequence)) - resources.getText(id) `should be equal to` repoCharSequence + + val result = philologyResources.getText(id, defaultCharSequence) + + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id, defaultCharSequence) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil } @Test - fun `Should return a CharSecuence from repository asking for an String`() { + fun `Should return a the default CharSequence asking for a text`() { + val defaultCharSequence: CharSequence = randomString() + configureResourceGetIdException(baseResources, id) + + val result = philologyResources.getText(id, defaultCharSequence) + + result `should be equal to` defaultCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getText(id, defaultCharSequence) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for an String`() { + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getString(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for an String`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + + val result = philologyResources.getString(id) + + result `should be equal to` someString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence from repository asking for an String`() { configureResourceGetText(baseResources, id, nameId, someCharSequence) configurePhilology(createRepository(nameId, null, repoCharSequence)) - resources.getString(id) `should be equal to` repoString + + val result = philologyResources.getString(id) + + result `should be equal to` repoString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for a formatted String`() { + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getString(id, formatArg) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a formatted String`() { + configureResourceGetText(baseResources, id, nameId, "$someCharSequence%s") + + val result = philologyResources.getString(id, formatArg) + + result `should be equal to` "$someString$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getText(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence from repository asking for a formatted String`() { + configureResourceGetText(baseResources, id, nameId, someCharSequence) + configurePhilology(createRepository(nameId, null, "$repoCharSequence%s")) + + val result = philologyResources.getString(id, formatArg) + + result `should be equal to` "$repoString$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getString(id, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for a quantity text`() { + val quantity = randomInt() + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getQuantityText(id, quantity) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a quantity text`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + + val result = philologyResources.getQuantityText(id, quantity) + + result `should be equal to` someCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + Verify on resourcesUtil that resourcesUtil.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a quantity text from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, repoCharSequence)) + + val result = philologyResources.getQuantityText(id, quantity) + + result `should be equal to` repoCharSequence + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on resourcesUtil that resourcesUtil.getQuantityText(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for an quantity String`() { + val quantity = randomInt() + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getQuantityString(id, quantity) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for an quantity String`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + + val result = philologyResources.getQuantityString(id, quantity) + + result `should be equal to` someString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for an quantity String from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, repoCharSequence)) + + val result = philologyResources.getQuantityString(id, quantity) + + result `should be equal to` repoString + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if id doesn't exist asking for a formatted quantity String`() { + configureResourceGetIdException(baseResources, id) + val quantity = randomInt() + + invoking { philologyResources.getQuantityString(id, quantity, formatArg) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a formatted quantity String`() { + val quantity = randomInt() + configureResourceQuantityString(baseResources, quantity, randomString()) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, "$someCharSequence%s") + + val result = philologyResources.getQuantityString(id, quantity, formatArg) + + result `should be equal to` someString + formatArg + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on baseResources that baseResources.getQuantityText(id, quantity) was called + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return a CharSequence asking for a formatted quantity text from repository`() { + val quantity = randomInt() + val quantityString = randomString() + configureResourceQuantityString(baseResources, quantity, quantityString) + configureResourceGetQuantityText(baseResources, id, nameId, quantity, someCharSequence) + configurePhilology(createRepository(nameId, quantityString, "$repoCharSequence%s")) + + val result = philologyResources.getQuantityString(id, quantity, formatArg) + + result `should be equal to` "$repoCharSequence$formatArg" + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getQuantityString(R.plurals.com_jcminarro_philology_quantity_string, quantity) + Verify on resourcesUtil that resourcesUtil.getQuantityString(id, quantity, formatArg) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for text array`() { + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getTextArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getTextArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings asking for a text array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + configureResourceGetTextArray(baseResources, id, nameId, textArray) + + val result = philologyResources.getTextArray(id) + + result `should be equal to` textArray + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getTextArray(id) was called + Verify on resourcesUtil that resourcesUtil.getTextArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings from repository asking for a text array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + configureResourceGetTextArray(baseResources, id, nameId, arrayOf(randomString(), randomString())) + configurePhilology(createRepository(nameId, textArray = textArray)) + + val result = philologyResources.getTextArray(id) + + result `should be equal to` textArray + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getTextArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist asking for a string array`() { + configureResourceGetIdException(baseResources, id) + + invoking { philologyResources.getStringArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getStringArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings asking for a string array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + val expectedResult = textArray.map { it.toString() }.toTypedArray() + configureResourceGetTextArray(baseResources, id, nameId, textArray) + + val result = philologyResources.getStringArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on baseResources that baseResources.getTextArray(id) was called + Verify on resourcesUtil that resourcesUtil.getStringArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return an array of strings from repository asking for a string array`() { + val textArray: Array = arrayOf(randomString(), randomString()) + val expectedResult = textArray.map { it.toString() }.toTypedArray() + configureResourceGetTextArray(baseResources, id, nameId, arrayOf(randomString(), randomString())) + configurePhilology(createRepository(nameId, textArray = textArray)) + + val result = philologyResources.getStringArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.configuration was called + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getStringArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getAnimation`() { + val id = randomInt() + When calling baseResources.getAnimation(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getAnimation(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getAnimation(id) was called + Verify on resourcesUtil that resourcesUtil.getAnimation(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return animation calling getAnimation`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getAnimation(id) doReturn expectedResult + + val result = philologyResources.getAnimation(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getAnimation(id) was called + Verify on resourcesUtil that resourcesUtil.getAnimation(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return displayMetrics calling getDisplayMetrics`() { + val expectedResult: DisplayMetrics = mock() + When calling baseResources.displayMetrics doReturn expectedResult + + val result = philologyResources.getDisplayMetrics() + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.displayMetrics was called + Verify on resourcesUtil that resourcesUtil.getDisplayMetrics() was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + When calling baseResources.getDrawableForDensity(id, density) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.getDrawableForDensity(id, density) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawableForDensity(id, density) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawableForDensity(id, density) doReturn expectedResult + + val result = philologyResources.getDrawableForDensity(id, density) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawableForDensity(id, density) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getDrawableForDensity(id, density, theme) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.getDrawableForDensity(id, density, theme) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDrawableForDensity(id, density, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawableForDensity`() { + val id = randomInt() + val density = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawableForDensity(id, density, theme) doReturn expectedResult + + val result = philologyResources.getDrawableForDensity(id, density, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawableForDensity(id, density, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawableForDensity(id, density, theme) was called + `Verify no further interactions` on baseResources + } + + @Test + fun `Should return configuration calling getConfiguration`() { + val result = philologyResources.getConfiguration() + + result `should be equal to` configuration + Verify on baseResources that baseResources.configuration was called + Verify on resourcesUtil that resourcesUtil.getConfiguration() was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception calling obtainAttributes`() { + val set: AttributeSet = mock() + val attrs: IntArray = intArrayOf(randomInt()) + When calling baseResources.obtainAttributes(set, attrs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.obtainAttributes(set, attrs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.obtainAttributes(set, attrs) was called + Verify on resourcesUtil that resourcesUtil.obtainAttributes(set, attrs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return animation calling obtainAttributes`() { + val set: AttributeSet = mock() + val attrs: IntArray = intArrayOf(randomInt()) + val expectedResult: TypedArray = mock() + When calling baseResources.obtainAttributes(set, attrs) doReturn expectedResult + + val result = philologyResources.obtainAttributes(set, attrs) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.obtainAttributes(set, attrs) was called + Verify on resourcesUtil that resourcesUtil.obtainAttributes(set, attrs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling obtainTypedArray`() { + val id = randomInt() + When calling baseResources.obtainTypedArray(id) doThrow Resources.NotFoundException::class + + invoking { resourcesUtil.obtainTypedArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.obtainTypedArray(id) was called + Verify on resourcesUtil that resourcesUtil.obtainTypedArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return TypedArray calling obtainTypedArray`() { + val id = randomInt() + val expectedResult: TypedArray = mock() + When calling baseResources.obtainTypedArray(id) doReturn expectedResult + + val result = resourcesUtil.obtainTypedArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.obtainTypedArray(id) was called + Verify on resourcesUtil that resourcesUtil.obtainTypedArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimensionPixelSize`() { + val id = randomInt() + When calling baseResources.getDimensionPixelSize(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDimensionPixelSize(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimensionPixelSize(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelSize(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return dimension calling getDimensionPixelSize`() { + val id = randomInt() + val expectedResult: Int = randomInt() + When calling baseResources.getDimensionPixelSize(id) doReturn expectedResult + + val result = philologyResources.getDimensionPixelSize(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimensionPixelSize(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelSize(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getIntArray`() { + val id = randomInt() + When calling baseResources.getIntArray(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getIntArray(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getIntArray(id) was called + Verify on resourcesUtil that resourcesUtil.getIntArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return intArray calling getIntArray`() { + val id = randomInt() + val expectedResult: IntArray = intArrayOf(randomInt(), randomInt(), randomInt()) + When calling baseResources.getIntArray(id) doReturn expectedResult + + val result = philologyResources.getIntArray(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getIntArray(id) was called + Verify on resourcesUtil that resourcesUtil.getIntArray(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getValue`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValue(id, typedValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getValue(id, typedValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValue(id, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(id, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return value calling getValue`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + philologyResources.getValue(id, typedValue, resolveRefs) + + Verify on baseResources that baseResources.getValue(id, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(id, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given name doesn't exist calling getValue`() { + val name = randomString() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValue(name, typedValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getValue(name, typedValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValue(name, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(name, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return value calling getValue`() { + val name = randomString() + val typedValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + philologyResources.getValue(name, typedValue, resolveRefs) + + Verify on baseResources that baseResources.getValue(name, typedValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValue(name, typedValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourcePackageName`() { + val id = randomInt() + When calling baseResources.getResourcePackageName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourcePackageName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourcePackageName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourcePackageName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return package calling getResourcePackageName`() { + val id = randomInt() + val expectedResult: String = randomString() + When calling baseResources.getResourcePackageName(id) doReturn expectedResult + + val result = philologyResources.getResourcePackageName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourcePackageName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourcePackageName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResourceFd`() { + val id = randomInt() + When calling baseResources.openRawResourceFd(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.openRawResourceFd(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.openRawResourceFd(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResourceFd(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return assetFileDescriptor calling openRawResourceFd`() { + val id = randomInt() + val expectedResult: AssetFileDescriptor = mock() + When calling baseResources.openRawResourceFd(id) doReturn expectedResult + + val result = philologyResources.openRawResourceFd(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResourceFd(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResourceFd(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimension`() { + val id = randomInt() + When calling baseResources.getDimension(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDimension(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimension(id) was called + Verify on resourcesUtil that resourcesUtil.getDimension(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return dimension calling getDimension`() { + val id = randomInt() + val expectedResult = randomFloat() + When calling baseResources.getDimension(id) doReturn expectedResult + + val result = philologyResources.getDimension(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimension(id) was called + Verify on resourcesUtil that resourcesUtil.getDimension(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColorStateList`() { + val id = randomInt() + When calling baseResources.getColorStateList(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getColorStateList(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColorStateList(id) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return colorStateList calling getColorStateList`() { + val id = randomInt() + val expectedResult: ColorStateList = mock() + When calling baseResources.getColorStateList(id) doReturn expectedResult + + val result = philologyResources.getColorStateList(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColorStateList(id) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColorStateList`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getColorStateList(id, theme) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.getColorStateList(id, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getColorStateList(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return colorStateList calling getColorStateList`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: ColorStateList = mock() + When calling baseResources.getColorStateList(id, theme) doReturn expectedResult + + val result = philologyResources.getColorStateList(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColorStateList(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColorStateList(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getBoolean`() { + val id = randomInt() + When calling baseResources.getBoolean(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getBoolean(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getBoolean(id) was called + Verify on resourcesUtil that resourcesUtil.getBoolean(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return boolean calling getBoolean`() { + val id = randomInt() + val expectedResult = randomBoolean() + When calling baseResources.getBoolean(id) doReturn expectedResult + + val result = philologyResources.getBoolean(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getBoolean(id) was called + Verify on resourcesUtil that resourcesUtil.getBoolean(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getIdentifier`() { + val name = randomString() + val defType = randomString() + val defPackage = randomString() + When calling baseResources.getIdentifier(name, defType, defPackage) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getIdentifier(name, defType, defPackage) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getIdentifier(name, defType, defPackage) was called + Verify on resourcesUtil that resourcesUtil.getIdentifier(name, defType, defPackage) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return integer calling getIdentifier`() { + val name = randomString() + val defType = randomString() + val defPackage = randomString() + val expectedResult = randomInt() + When calling baseResources.getIdentifier(name, defType, defPackage) doReturn expectedResult + + val result = philologyResources.getIdentifier(name, defType, defPackage) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getIdentifier(name, defType, defPackage) was called + Verify on resourcesUtil that resourcesUtil.getIdentifier(name, defType, defPackage) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColor`() { + val id = randomInt() + When calling baseResources.getColor(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getColor(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColor(id) was called + Verify on resourcesUtil that resourcesUtil.getColor(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return color calling getColor`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getColor(id) doReturn expectedResult + + val result = philologyResources.getColor(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColor(id) was called + Verify on resourcesUtil that resourcesUtil.getColor(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getColor`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getColor(id, theme) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getColor(id, theme) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getColor(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColor(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return color calling getColor`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult = randomInt() + When calling baseResources.getColor(id, theme) doReturn expectedResult + + val result = philologyResources.getColor(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getColor(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getColor(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should call to updateConfiguration`() { + val newConf: Configuration = mock() + val newMetrics: DisplayMetrics = mock() + + philologyResources.updateConfiguration(newConf, newMetrics) + + Verify on baseResources that baseResources.updateConfiguration(newConf, newMetrics) was called + Verify on resourcesUtil that resourcesUtil.updateConfiguration(newConf, newMetrics) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResource`() { + val id = randomInt() + When calling baseResources.openRawResource(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.openRawResource(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.openRawResource(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return inputStream calling openRawResource`() { + val id = randomInt() + val expectedResult: InputStream = mock() + When calling baseResources.openRawResource(id) doReturn expectedResult + + val result = philologyResources.openRawResource(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResource(id) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling openRawResource`() { + val id = randomInt() + val typedValue: TypedValue = mock() + When calling baseResources.openRawResource(id, typedValue) doThrow Resources + .NotFoundException::class + + invoking { philologyResources.openRawResource(id, typedValue) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.openRawResource(id, typedValue) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id, typedValue) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return inputStream calling openRawResource`() { + val id = randomInt() + val typedValue: TypedValue = mock() + val expectedResult: InputStream = mock() + When calling baseResources.openRawResource(id, typedValue) doReturn expectedResult + + val result = philologyResources.openRawResource(id, typedValue) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.openRawResource(id, typedValue) was called + Verify on resourcesUtil that resourcesUtil.openRawResource(id, typedValue) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getMovie`() { + val id = randomInt() + When calling baseResources.getMovie(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getMovie(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getMovie(id) was called + Verify on resourcesUtil that resourcesUtil.getMovie(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Movie calling getMovie`() { + val id = randomInt() + val expectedResult: Movie = mock() + When calling baseResources.getMovie(id) doReturn expectedResult + + val result = philologyResources.getMovie(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getMovie(id) was called + Verify on resourcesUtil that resourcesUtil.getMovie(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getInteger`() { + val id = randomInt() + When calling baseResources.getInteger(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getInteger(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getInteger(id) was called + Verify on resourcesUtil that resourcesUtil.getInteger(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Integer calling getInteger`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getInteger(id) doReturn expectedResult + + val result = philologyResources.getInteger(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getInteger(id) was called + Verify on resourcesUtil that resourcesUtil.getInteger(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an XmlPullParserException if the given id doesn't exist calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtras(parser, outBundle) doThrow XmlPullParserException::class + + invoking { philologyResources.parseBundleExtras(parser, outBundle) } `should throw` XmlPullParserException::class + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an IOException if the given id doesn't exist calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtras(parser, outBundle) doThrow IOException::class + + invoking { philologyResources.parseBundleExtras(parser, outBundle) } `should throw` IOException::class + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Integer calling parseBundleExtras`() { + val parser: XmlResourceParser = mock() + val outBundle: Bundle = mock() + + philologyResources.parseBundleExtras(parser, outBundle) + + Verify on baseResources that baseResources.parseBundleExtras(parser, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtras(parser, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawable`() { + val id = randomInt() + When calling baseResources.getDrawable(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDrawable(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDrawable(id) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawable`() { + val id = randomInt() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawable(id) doReturn expectedResult + + val result = philologyResources.getDrawable(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawable(id) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDrawable`() { + val id = randomInt() + val theme: Resources.Theme = mock() + When calling baseResources.getDrawable(id, theme) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDrawable(id, theme) } `should throw` Resources + .NotFoundException::class + + Verify on baseResources that baseResources.getDrawable(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getDrawable`() { + val id = randomInt() + val theme: Resources.Theme = mock() + val expectedResult: Drawable = mock() + When calling baseResources.getDrawable(id, theme) doReturn expectedResult + + val result = philologyResources.getDrawable(id, theme) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDrawable(id, theme) was called + Verify on resourcesUtil that resourcesUtil.getDrawable(id, theme) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceTypeName`() { + val id = randomInt() + When calling baseResources.getResourceTypeName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourceTypeName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceTypeName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceTypeName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling getResourceTypeName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceTypeName(id) doReturn expectedResult + + val result = philologyResources.getResourceTypeName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceTypeName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceTypeName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getLayout`() { + val id = randomInt() + When calling baseResources.getLayout(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getLayout(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getLayout(id) was called + Verify on resourcesUtil that resourcesUtil.getLayout(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return layout calling getLayout`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getLayout(id) doReturn expectedResult + + val result = philologyResources.getLayout(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getLayout(id) was called + Verify on resourcesUtil that resourcesUtil.getLayout(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getFont`() { + val id = randomInt() + When calling baseResources.getFont(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getFont(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getFont(id) was called + Verify on resourcesUtil that resourcesUtil.getFont(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return typeFace calling getFont`() { + val id = randomInt() + val expectedResult: Typeface = mock() + When calling baseResources.getFont(id) doReturn expectedResult + + val result = philologyResources.getFont(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getFont(id) was called + Verify on resourcesUtil that resourcesUtil.getFont(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getXml`() { + val id = randomInt() + When calling baseResources.getXml(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getXml(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getXml(id) was called + Verify on resourcesUtil that resourcesUtil.getXml(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return xml calling getXml`() { + val id = randomInt() + val expectedResult: XmlResourceParser = mock() + When calling baseResources.getXml(id) doReturn expectedResult + + val result = philologyResources.getXml(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getXml(id) was called + Verify on resourcesUtil that resourcesUtil.getXml(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceName`() { + val id = randomInt() + When calling baseResources.getResourceName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourceName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling getResourceName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceName(id) doReturn expectedResult + + val result = philologyResources.getResourceName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling parseBundleExtra`() { + val tagName: String = randomString() + val attrs: AttributeSet = mock() + val outBundle: Bundle = mock() + When calling baseResources.parseBundleExtra(tagName, attrs, outBundle) doThrow XmlPullParserException::class + + invoking { philologyResources.parseBundleExtra(tagName, attrs, outBundle) } `should throw` XmlPullParserException::class + + Verify on baseResources that baseResources.parseBundleExtra(tagName, attrs, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling parseBundleExtra`() { + val tagName: String = randomString() + val attrs: AttributeSet = mock() + val outBundle: Bundle = mock() + + philologyResources.parseBundleExtra(tagName, attrs, outBundle) + + Verify on baseResources that baseResources.parseBundleExtra(tagName, attrs, outBundle) was called + Verify on resourcesUtil that resourcesUtil.parseBundleExtra(tagName, attrs, outBundle) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getDimensionPixelOffset`() { + val id = randomInt() + When calling baseResources.getDimensionPixelOffset(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getDimensionPixelOffset(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getDimensionPixelOffset(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelOffset(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Integer calling getDimensionPixelOffset`() { + val id = randomInt() + val expectedResult = randomInt() + When calling baseResources.getDimensionPixelOffset(id) doReturn expectedResult + + val result = philologyResources.getDimensionPixelOffset(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getDimensionPixelOffset(id) was called + Verify on resourcesUtil that resourcesUtil.getDimensionPixelOffset(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getValueForDensity`() { + val id = randomInt() + val density = randomInt() + val outValue: TypedValue = mock() + val resolveRefs = randomBoolean() + When calling baseResources.getValueForDensity(id, density, outValue, resolveRefs) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getValueForDensity(id, density, outValue, resolveRefs) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getValueForDensity(id, density, outValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Drawable calling getValueForDensity`() { + val id = randomInt() + val density = randomInt() + val outValue: TypedValue = mock() + val resolveRefs = randomBoolean() + + philologyResources.getValueForDensity(id, density, outValue, resolveRefs) + + Verify on baseResources that baseResources.getValueForDensity(id, density, outValue, resolveRefs) was called + Verify on resourcesUtil that resourcesUtil.getValueForDensity(id, density, outValue, resolveRefs) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getResourceEntryName`() { + val id = randomInt() + When calling baseResources.getResourceEntryName(id) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getResourceEntryName(id) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return Name calling getResourceEntryName`() { + val id = randomInt() + val expectedResult = randomString() + When calling baseResources.getResourceEntryName(id) doReturn expectedResult + + val result = philologyResources.getResourceEntryName(id) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getResourceEntryName(id) was called + Verify on resourcesUtil that resourcesUtil.getResourceEntryName(id) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should throw an exception if the given id doesn't exist calling getFraction`() { + val id = randomInt() + val base = randomInt() + val pbase = randomInt() + When calling baseResources.getFraction(id, base, pbase) doThrow Resources.NotFoundException::class + + invoking { philologyResources.getFraction(id, base, pbase) } `should throw` Resources.NotFoundException::class + + Verify on baseResources that baseResources.getFraction(id, base, pbase) was called + Verify on resourcesUtil that resourcesUtil.getFraction(id, base, pbase) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil + } + + @Test + fun `Should return dimension calling getFraction`() { + val id = randomInt() + val base = randomInt() + val pbase = randomInt() + val expectedResult = randomFloat() + When calling baseResources.getFraction(id, base, pbase) doReturn expectedResult + + val result = philologyResources.getFraction(id, base, pbase) + + result `should be equal to` expectedResult + Verify on baseResources that baseResources.getFraction(id, base, pbase) was called + Verify on resourcesUtil that resourcesUtil.getFraction(id, base, pbase) was called + `Verify no further interactions` on baseResources + `Verify no further interactions` on resourcesUtil } } \ No newline at end of file