Skip to content

Commit

Permalink
use assertJ assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
VREMSoftwareDevelopment committed Feb 17, 2024
1 parent b454910 commit 4093b1f
Show file tree
Hide file tree
Showing 128 changed files with 1,664 additions and 1,769 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation 'org.slf4j:slf4j-simple:2.0.12'
testImplementation 'org.assertj:assertj-core:3.25.3'
// Android Test Dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
Expand Down
4 changes: 2 additions & 2 deletions app/build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Build Properties
#Thu Feb 15 07:58:17 EST 2024
version_build=9
#Sat Feb 17 09:31:26 EST 2024
version_build=10
version_major=3
version_minor=1
version_patch=2
Expand Down
20 changes: 10 additions & 10 deletions app/src/test/kotlin/com/vrem/util/CompatUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import android.net.wifi.WifiSsid
import android.os.Build
import android.util.DisplayMetrics
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -85,8 +85,8 @@ class CompatUtilsTest {
// execute
val actual: Context = context.createContext(newLocale)
// validate
assertEquals(contextWrapper, actual)
assertEquals(context, (actual as ContextWrapper).baseContext)
assertThat(actual).isEqualTo(contextWrapper)
assertThat((actual as ContextWrapper).baseContext).isEqualTo(context)
verify(configuration).setLocale(newLocale)
verify(context).createConfigurationContext(configuration)
verify(context).resources
Expand All @@ -104,7 +104,7 @@ class CompatUtilsTest {
// execute
val actual = context.packageInfo()
// validate
assertEquals(packageInfo, actual)
assertThat(actual).isEqualTo(packageInfo)
verify(packageManager).getPackageInfo(eq(packageName), any<PackageInfoFlags>())
verify(context).packageName
verify(context).packageManager
Expand All @@ -121,7 +121,7 @@ class CompatUtilsTest {
// execute
val actual = context.packageInfo()
// validate
assertEquals(packageInfo, actual)
assertThat(actual).isEqualTo(packageInfo)
verify(packageManager).getPackageInfo(packageName, 0)
verify(context).packageName
verify(context).packageManager
Expand All @@ -137,7 +137,7 @@ class CompatUtilsTest {
// execute
val actual = scanResult.ssid()
// validate
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
verify(scanResult).wifiSsid
}

Expand All @@ -148,7 +148,7 @@ class CompatUtilsTest {
// execute
val actual = scanResult.ssid()
// validate
assertEquals(String.EMPTY, actual)
assertThat(actual).isEqualTo(String.EMPTY)
verify(scanResult).wifiSsid
}

Expand All @@ -160,7 +160,7 @@ class CompatUtilsTest {
// execute
val actual = scanResult.ssid()
// validate
assertEquals(String.EMPTY, actual)
assertThat(actual).isEqualTo(String.EMPTY)
verify(scanResult).wifiSsid
}

Expand All @@ -175,7 +175,7 @@ class CompatUtilsTest {
// execute
val actual = scanResult.ssid()
// validate
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}

@Test
Expand All @@ -187,7 +187,7 @@ class CompatUtilsTest {
// execute
val actual = scanResult.ssid()
// validate
assertEquals(String.EMPTY, actual)
assertThat(actual).isEqualTo(String.EMPTY)
}

}
21 changes: 10 additions & 11 deletions app/src/test/kotlin/com/vrem/util/EnumUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
package com.vrem.util

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class EnumUtilsTest {
Expand All @@ -30,9 +29,9 @@ class EnumUtilsTest {
// execute
val actual = ordinals(TestObject.entries)
// validate
assertEquals(expected.size, actual.size)
assertThat(actual).hasSize(expected.size)
expected.forEach {
assertTrue(actual.contains("" + it.ordinal))
assertThat(actual).contains("" + it.ordinal)
}
}

Expand Down Expand Up @@ -65,8 +64,8 @@ class EnumUtilsTest {
// execute
val actual = findSet(TestObject.entries, ordinals, expected)
// validate
assertEquals(1, actual.size)
assertTrue(actual.contains(expected))
assertThat(actual).hasSize(1)
assertThat(actual).contains(expected)
}

@Test
Expand All @@ -75,7 +74,7 @@ class EnumUtilsTest {
// execute
val actual = findOne(TestObject.entries, it.ordinal, TestObject.VALUE2)
// validate
assertEquals(it, actual)
assertThat(actual).isEqualTo(it)
}
}

Expand All @@ -87,7 +86,7 @@ class EnumUtilsTest {
// execute
val actual = findOne(TestObject.entries, index, expected)
// validate
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}

@Test
Expand All @@ -98,13 +97,13 @@ class EnumUtilsTest {
// execute
val actual = findOne(TestObject.entries, index, expected)
// validate
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}

private fun validate(expected: Collection<TestObject>, actual: Collection<TestObject>) {
assertEquals(expected.size, actual.size)
assertThat(actual).hasSize(expected.size)
expected.forEach {
assertTrue(actual.contains(it))
assertThat(actual).contains(it)
}
}

Expand Down
7 changes: 3 additions & 4 deletions app/src/test/kotlin/com/vrem/util/FileUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ package com.vrem.util

import android.content.res.Resources
import android.content.res.Resources.NotFoundException
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
Expand Down Expand Up @@ -49,7 +48,7 @@ class FileUtilsTest {
// execute
val actual: String = readFile(resources, id)
// validate
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
verify(resources).openRawResource(id)
}

Expand All @@ -61,7 +60,7 @@ class FileUtilsTest {
// execute
val actual: String = readFile(resources, id)
// validate
assertTrue(actual.isEmpty())
assertThat(actual).isEmpty()
verify(resources).openRawResource(id)
}
}
42 changes: 21 additions & 21 deletions app/src/test/kotlin/com/vrem/util/LocaleUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.vrem.util

import org.junit.Assert.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import java.util.Locale

Expand All @@ -27,8 +27,8 @@ class LocaleUtilsTest {
// execute
val actual = allCountries()
// validate
assertTrue(actual.size >= 2)
assertTrue(actual[0].country < actual[actual.size - 1].country)
assertThat(actual.size).isGreaterThanOrEqualTo(2)
assertThat(actual[0].country).isLessThan(actual[actual.size - 1].country)
}

@Test
Expand All @@ -38,40 +38,40 @@ class LocaleUtilsTest {
// execute
val actual = findByCountryCode(expected.country)
// validate
assertEquals(expected, actual)
assertEquals(expected.country, actual.country)
assertEquals(expected.displayCountry, actual.displayCountry)
assertNotEquals(expected.country, expected.displayCountry)
assertNotEquals(actual.country, actual.displayCountry)
assertThat(actual).isEqualTo(expected)
assertThat(actual.country).isEqualTo(expected.country)
assertThat(actual.displayCountry).isEqualTo(expected.displayCountry)
assertThat(expected.displayCountry).isNotEqualTo(expected.country)
assertThat(actual.displayCountry).isNotEqualTo(actual.country)
}

@Test
fun findByCountryCodeWithUnknownCode() {
// execute
val actual = findByCountryCode("WW")
// validate
assertEquals(Locale.getDefault(), actual)
assertThat(actual).isEqualTo(Locale.getDefault())
}

@Test
fun toLanguageTagWithKnownCode() {
assertEquals(Locale.US.language + "_" + Locale.US.country, toLanguageTag(Locale.US))
assertEquals(Locale.ENGLISH.language + "_", toLanguageTag(Locale.ENGLISH))
assertThat(toLanguageTag(Locale.US)).isEqualTo(Locale.US.language + "_" + Locale.US.country)
assertThat(toLanguageTag(Locale.ENGLISH)).isEqualTo(Locale.ENGLISH.language + "_")
}

@Test
fun findByLanguageTagWithUnknownTag() {
val defaultLocal = Locale.getDefault()
assertEquals(defaultLocal, findByLanguageTag(String.EMPTY))
assertEquals(defaultLocal, findByLanguageTag("WW"))
assertEquals(defaultLocal, findByLanguageTag("WW_HH_TT"))
assertThat(findByLanguageTag(String.EMPTY)).isEqualTo(defaultLocal)
assertThat(findByLanguageTag("WW")).isEqualTo(defaultLocal)
assertThat(findByLanguageTag("WW_HH_TT")).isEqualTo(defaultLocal)
}

@Test
fun findByLanguageTagWithKnownTag() {
assertEquals(Locale.SIMPLIFIED_CHINESE, findByLanguageTag(toLanguageTag(Locale.SIMPLIFIED_CHINESE)))
assertEquals(Locale.TRADITIONAL_CHINESE, findByLanguageTag(toLanguageTag(Locale.TRADITIONAL_CHINESE)))
assertEquals(Locale.ENGLISH, findByLanguageTag(toLanguageTag(Locale.ENGLISH)))
assertThat(findByLanguageTag(toLanguageTag(Locale.SIMPLIFIED_CHINESE))).isEqualTo(Locale.SIMPLIFIED_CHINESE)
assertThat(findByLanguageTag(toLanguageTag(Locale.TRADITIONAL_CHINESE))).isEqualTo(Locale.TRADITIONAL_CHINESE)
assertThat(findByLanguageTag(toLanguageTag(Locale.ENGLISH))).isEqualTo(Locale.ENGLISH)
}

@Test
Expand All @@ -98,19 +98,19 @@ class LocaleUtilsTest {
// execute
val actual = supportedLanguages()
// validate
assertEquals(expected.size, actual.size)
assertThat(actual).hasSize(expected.size)
for (locale in expected) {
assertTrue(actual.contains(locale))
assertThat(actual).contains(locale)
}
}

@Test
fun currentDefaultCountryCode() {
assertEquals(Locale.getDefault().country, defaultCountryCode())
assertThat(defaultCountryCode()).isEqualTo(Locale.getDefault().country)
}

@Test
fun currentDefaultLanguageTag() {
assertEquals(toLanguageTag(Locale.getDefault()), defaultLanguageTag())
assertThat(defaultLanguageTag()).isEqualTo(toLanguageTag(Locale.getDefault()))
}
}
10 changes: 5 additions & 5 deletions app/src/test/kotlin/com/vrem/util/StringUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.vrem.util

import org.junit.Assert.assertEquals
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import java.util.Locale

Expand All @@ -31,7 +31,7 @@ class StringUtilsTest {
// execute
val actual: String = value.specialTrim()
// verify
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}

@Test
Expand All @@ -42,7 +42,7 @@ class StringUtilsTest {
// execute
val actual: String = value.toCapitalize(Locale.US)
// verify
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}

@Test
Expand All @@ -53,7 +53,7 @@ class StringUtilsTest {
// execute
val actual: String = String.nullToEmpty(value)
// verify
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}

@Test
Expand All @@ -64,7 +64,7 @@ class StringUtilsTest {
// execute
val actual: String = String.nullToEmpty(value)
// verify
assertEquals(expected, actual)
assertThat(actual).isEqualTo(expected)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.ActionBar
import androidx.appcompat.widget.Toolbar
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mockito.kotlin.*

Expand Down Expand Up @@ -55,7 +55,7 @@ class ActivityUtilsTest {
// execute
val actual = mainActivity.setupToolbar()
// validate
assertEquals(toolbar, actual)
assertThat(actual).isEqualTo(toolbar)
verify(mainActivity).findViewById<View>(R.id.toolbar)
verify(mainActivity).supportActionBar
verify(mainActivity).setSupportActionBar(toolbar)
Expand Down
Loading

0 comments on commit 4093b1f

Please sign in to comment.