Skip to content

Commit

Permalink
Merge pull request #79 from infinum/develop
Browse files Browse the repository at this point in the history
Update master with 1.4.1 release
  • Loading branch information
KCeh authored Aug 21, 2024
2 parents 164176a + 2ac74f8 commit ed8d4a5
Show file tree
Hide file tree
Showing 32 changed files with 584 additions and 210 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ Then add the following dependencies in your app `build.gradle` or `build.gradle.
**Groovy**

```groovy
def sentinelVersion = "1.4.0"
def sentinelVersion = "1.4.1"
debugImplementation "com.infinum.sentinel:sentinel:$sentinelVersion"
releaseImplementation "com.infinum.sentinel:sentinel-no-op:$sentinelVersion"
```

**KotlinDSL**

```kotlin
val sentinelVersion = "1.4.0"
val sentinelVersion = "1.4.1"
debugImplementation("com.infinum.sentinel:sentinel:$sentinelVersion")
releaseImplementation("com.infinum.sentinel:sentinel-no-op:$sentinelVersion")
```
Expand Down
2 changes: 1 addition & 1 deletion config.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
def major = 1
def minor = 4
def patch = 0
def patch = 1

buildConfig = [
"minSdk" : 21,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
sentinel = "1.4.0"
sentinel = "1.4.1"
gradle = "8.3.2"
kotlin = "1.9.22"
coroutines = "1.8.0"
Expand Down
6 changes: 3 additions & 3 deletions sentinel/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<uses-sdk tools:overrideLibrary="androidx.security"/>

<application
android:name=".ui.SentinelTestApplication"
android:name="com.infinum.sentinel.ui.SentinelTestApplication"
android:label="@string/sentinel_name">
<activity
android:name=".ui.main.SentinelActivity"
android:name="com.infinum.sentinel.ui.main.SentinelActivity"
android:label="@string/sentinel_name"
android:theme="@style/Sentinel.Theme" />
android:theme="@style/Sentinel.Theme"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ internal class SentinelTests {
fun sentinel_show() {
Sentinel.show()

intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(2))
intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(1))
}

// @Test
// @SmallTest
// @RequiresDevice
// fun sentinel_showDevice() {
// val instance = Sentinel.watch(context)
//
// instance.show()
//
// intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(1))
// }
@Test
@SmallTest
fun sentinel_showDevice() {
val instance = Sentinel.watch()

instance.show()

intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class ApplicationCollectorTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import com.infinum.sentinel.ui.SentinelTestApplication
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.util.ReflectionHelpers

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class DeviceCollectorDeviceTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import com.infinum.sentinel.ui.SentinelTestApplication
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.util.ReflectionHelpers

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class DeviceCollectorEmulatorTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import com.infinum.sentinel.ui.SentinelTestApplication
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class PermissionsCollectorTests {

companion object {

private val APPENDED_PERMISSIONS = mapOf(Manifest.permission.REORDER_TASKS to true)
private val APPENDED_PERMISSIONS = mapOf(
Manifest.permission.REORDER_TASKS to true,
Manifest.permission.POST_NOTIFICATIONS to false,
Manifest.permission.WAKE_LOCK to true,
Manifest.permission.ACCESS_NETWORK_STATE to true,
Manifest.permission.RECEIVE_BOOT_COMPLETED to true,
Manifest.permission.FOREGROUND_SERVICE to true,
"com.infinum.sentinel.test.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" to true
)

lateinit var actualPermissions: Map<String, Boolean>

Expand All @@ -40,13 +46,15 @@ internal class PermissionsCollectorTests {
fun permissions_notDeclared() {
assertTrue(actualPermissions.isNotEmpty())
assertEquals(APPENDED_PERMISSIONS.size, actualPermissions.size)
assertEquals(
APPENDED_PERMISSIONS.containsKey(Manifest.permission.REORDER_TASKS),
actualPermissions.containsKey(Manifest.permission.REORDER_TASKS)
)
assertEquals(
APPENDED_PERMISSIONS[Manifest.permission.REORDER_TASKS],
actualPermissions[Manifest.permission.REORDER_TASKS]
)
APPENDED_PERMISSIONS.forEach { (permission, expectedStatus) ->
assertEquals(
APPENDED_PERMISSIONS.containsKey(permission),
actualPermissions.containsKey(permission)
)
assertEquals(
expectedStatus,
actualPermissions[permission]
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class PreferencesCollectorTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ package com.infinum.sentinel.data.sources.raw.collectors

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.infinum.sentinel.ui.tools.AppInfoTool
import com.infinum.sentinel.Sentinel
import com.infinum.sentinel.ui.tools.DummyTool
import com.infinum.sentinel.ui.tools.NoNameTool
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class ToolsCollectorTests {

Expand All @@ -33,20 +31,20 @@ internal class ToolsCollectorTests {
@SmallTest
fun tools_AreEmpty() {
val collector = ToolsCollector(setOf())
val expectedTools = setOf(AppInfoTool())
val expectedTools = setOf<Sentinel.Tool>()

val actualTools = collector()

assertEquals(expectedTools.size, actualTools.size)
assertTrue(actualTools.isNotEmpty())
assertTrue(actualTools.isEmpty())
assertEquals(expectedTools, actualTools)
}

@Test
@SmallTest
fun tools_AreUnique() {
val collector = ToolsCollector(setOf(dummyTool, dummyTool))
val expectedTools = setOf(dummyTool, AppInfoTool())
val expectedTools = setOf(dummyTool)

val actualTools = collector()

Expand All @@ -59,7 +57,7 @@ internal class ToolsCollectorTests {
@SmallTest
fun tools_AreValid() {
val collector = ToolsCollector(setOf(dummyTool, noNameTool))
val expectedTools = setOf(dummyTool, AppInfoTool())
val expectedTools = setOf(dummyTool)

val actualTools = collector()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.util.ReflectionHelpers

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class HtmlStringBuilderTests {

Expand Down Expand Up @@ -123,6 +121,33 @@ internal class HtmlStringBuilderTests {
?.use { it.readText() }
.orEmpty()

private fun checkDeviceSpecificFields(html: String): String {
val fields = listOf(
"screen_width",
"screen_height",
"screen_size",
"screen_density",
"font_scale"
)

val fieldPatterns = fields.map { field ->
field to Regex("""<div>$field:\s*[^<]*</div>""")
}

var updatedHtml = html

fieldPatterns.forEach { (field, pattern) ->
val matchResult = pattern.find(updatedHtml)
if (matchResult == null) {
throw AssertionError("Field $field is missing in the device object")
} else {
updatedHtml = updatedHtml.replace(matchResult.value, """<div>$field: </div>""")
}
}

return updatedHtml
}

@Before
fun preferences_deleteDir() {
val prefsDirectory =
Expand All @@ -144,7 +169,8 @@ internal class HtmlStringBuilderTests {

assertNotNull(actualData)
assertTrue(actualData.isNotBlank())
assertEquals(EXPECTED_DATA_NO_PREFERENCES, actualData)
val cleanedUpData = checkDeviceSpecificFields(actualData)
assertEquals(EXPECTED_DATA_NO_PREFERENCES, cleanedUpData)
}

@Test
Expand All @@ -167,6 +193,7 @@ internal class HtmlStringBuilderTests {

assertNotNull(actualData)
assertTrue(actualData.isNotBlank())
assertEquals(EXPECTED_DATA, actualData)
val cleanedUpData = checkDeviceSpecificFields(actualData)
assertEquals(EXPECTED_DATA, cleanedUpData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import com.infinum.sentinel.data.sources.raw.collectors.PreferencesCollector
import com.infinum.sentinel.domain.collectors.Collectors
import com.infinum.sentinel.ui.SentinelTestApplication
import java.io.File
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.util.ReflectionHelpers

@Ignore("This test is ignored because it's failing on CI")
@RunWith(AndroidJUnit4::class)
internal class JsonStringBuilderTests {

Expand Down Expand Up @@ -136,6 +135,27 @@ internal class JsonStringBuilderTests {
assertTrue(success)
}

private fun checkDeviceSpecificFields(json: JSONObject): JSONObject {
val device = json.optJSONObject("device") ?: throw AssertionError("Device object is missing")

val fields = listOf(
"screen_width",
"screen_height",
"screen_size",
"screen_density",
"font_scale"
)

fields.forEach { field ->
if (!device.has(field)) {
throw AssertionError("Field $field is missing in the device object")
}
device.put(field, "")
}

return json
}

@Test
@SmallTest
fun formatter_hasDataWithoutPreferences() {
Expand All @@ -147,7 +167,8 @@ internal class JsonStringBuilderTests {

assertNotNull(actualData)
assertTrue(actualData.isNotBlank())
assertEquals(EXPECTED_DATA_NO_PREFERENCES, actualData)
val cleanedUpData = checkDeviceSpecificFields(JSONObject(actualData))
assertEquals(EXPECTED_DATA_NO_PREFERENCES, cleanedUpData.toString())
}

@Test
Expand All @@ -171,6 +192,8 @@ internal class JsonStringBuilderTests {

assertNotNull(actualData)
assertTrue(actualData.isNotBlank())
assertEquals(EXPECTED_DATA, actualData)
assertTrue(actualData.isNotBlank())
val cleanedUpData = checkDeviceSpecificFields(JSONObject(actualData))
assertEquals(EXPECTED_DATA, cleanedUpData.toString())
}
}
Loading

0 comments on commit ed8d4a5

Please sign in to comment.