Add Notification profiles.

This commit is contained in:
Cody Henthorne
2021-12-08 13:22:36 -05:00
parent 31e0696395
commit 6c608e955e
106 changed files with 5692 additions and 238 deletions

View File

@@ -0,0 +1,42 @@
package org.thoughtcrime.securesms
import androidx.test.core.app.ApplicationProvider
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.dependencies.MockApplicationDependencyProvider
import org.thoughtcrime.securesms.keyvalue.KeyValueDataSet
import org.thoughtcrime.securesms.keyvalue.KeyValueStore
import org.thoughtcrime.securesms.keyvalue.MockKeyValuePersistentStorage
import org.thoughtcrime.securesms.keyvalue.SignalStore
/**
* Rule to setup [SignalStore] with a mock [KeyValueDataSet]. Must be used with Roboelectric.
*
* Can provide [defaultValues] to set the same values before each test and use [dataSet] directly to add any
* test specific values.
*
* The [dataSet] is reset at the beginning of each test to an empty state.
*/
class SignalStoreRule @JvmOverloads constructor(private val defaultValues: KeyValueDataSet.() -> Unit = {}) : TestRule {
var dataSet = KeyValueDataSet()
private set
override fun apply(base: Statement, description: Description): Statement {
return object : Statement() {
@Throws(Throwable::class)
override fun evaluate() {
if (!ApplicationDependencies.isInitialized()) {
ApplicationDependencies.init(ApplicationProvider.getApplicationContext(), MockApplicationDependencyProvider())
}
dataSet = KeyValueDataSet()
SignalStore.inject(KeyValueStore(MockKeyValuePersistentStorage.withDataSet(dataSet)))
defaultValues.invoke(dataSet)
base.evaluate()
}
}
}
}

View File

@@ -0,0 +1,167 @@
package org.thoughtcrime.securesms.database
import android.app.Application
import android.database.sqlite.SQLiteDatabase
import androidx.test.core.app.ApplicationProvider
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.containsInAnyOrder
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.dependencies.MockApplicationDependencyProvider
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfile
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.testing.TestDatabaseUtil
import java.time.DayOfWeek
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE, application = Application::class)
class NotificationProfileDatabaseTest {
private lateinit var db: SQLiteDatabase
private lateinit var database: NotificationProfileDatabase
@Before
fun setup() {
val sqlCipher = TestDatabaseUtil.inMemoryDatabase {
NotificationProfileDatabase.CREATE_TABLE.forEach { println(it); this.execSQL(it) }
NotificationProfileDatabase.CREATE_INDEXES.forEach { println(it); this.execSQL(it) }
}
if (!ApplicationDependencies.isInitialized()) {
ApplicationDependencies.init(ApplicationProvider.getApplicationContext(), MockApplicationDependencyProvider())
}
db = sqlCipher.writableDatabase
database = NotificationProfileDatabase(ApplicationProvider.getApplicationContext(), sqlCipher)
}
@After
fun tearDown() {
db.close()
}
@Test
fun `addProfile for profile with empty schedule and members`() {
val profile: NotificationProfile = database.createProfile(
name = "Profile",
emoji = "avatar",
color = AvatarColor.A210,
createdAt = 1000L
).profile
assertEquals(1, profile.id)
assertEquals("Profile", profile.name)
assertEquals("avatar", profile.emoji)
assertEquals(1000L, profile.createdAt)
assertEquals(1, profile.schedule.id)
val profiles = database.getProfiles()
assertEquals(1, profiles.size)
assertEquals(1, profiles[0].id)
assertEquals("Profile", profiles[0].name)
assertEquals("avatar", profiles[0].emoji)
assertEquals(1000L, profiles[0].createdAt)
assertEquals(1, profiles[0].schedule.id)
}
@Test
fun `updateProfile changes all updateable fields`() {
val profile: NotificationProfile = database.createProfile(
name = "Profile",
emoji = "avatar",
color = AvatarColor.A210,
createdAt = 1000L
).profile
val updatedProfile = database.updateProfile(
profile.copy(
name = "Profile 2",
emoji = "avatar 2",
allowAllCalls = true,
allowAllMentions = true
)
).profile
assertEquals("Profile 2", updatedProfile.name)
assertEquals("avatar 2", updatedProfile.emoji)
assertEquals(1000L, updatedProfile.createdAt)
assertTrue(updatedProfile.allowAllCalls)
assertTrue(updatedProfile.allowAllMentions)
}
@Test
fun `when allowed recipients change profile changes`() {
val profile: NotificationProfile = database.createProfile(
name = "Profile",
emoji = "avatar",
color = AvatarColor.A210,
createdAt = 1000L
).profile
assertFalse(profile.isRecipientAllowed(RecipientId.from(1)))
var updated = database.addAllowedRecipient(profile.id, RecipientId.from(1))
assertTrue(updated.isRecipientAllowed(RecipientId.from(1)))
updated = database.removeAllowedRecipient(profile.id, RecipientId.from(1))
assertFalse(updated.isRecipientAllowed(RecipientId.from(1)))
updated = database.updateProfile(updated.copy(allowedMembers = setOf(RecipientId.from(1)))).profile
assertTrue(updated.isRecipientAllowed(RecipientId.from(1)))
updated = database.updateProfile(updated.copy(allowedMembers = emptySet())).profile
assertFalse(updated.isRecipientAllowed(RecipientId.from(1)))
}
@Test
fun `when schedule change profile changes`() {
val profile: NotificationProfile = database.createProfile(
name = "Profile",
emoji = "avatar",
color = AvatarColor.A210,
createdAt = 1000L
).profile
assertFalse(profile.schedule.enabled)
assertEquals(900, profile.schedule.start)
assertEquals(1700, profile.schedule.end)
assertThat("Contains correct default days", profile.schedule.daysEnabled, containsInAnyOrder(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY))
database.updateSchedule(profile.schedule.copy(enabled = true, start = 800, end = 1800, daysEnabled = setOf(DayOfWeek.SUNDAY, DayOfWeek.FRIDAY)))
var updated = database.getProfile(profile.id)!!
assertTrue(updated.schedule.enabled)
assertEquals(800, updated.schedule.start)
assertEquals(1800, updated.schedule.end)
assertThat("Contains updated days days", updated.schedule.daysEnabled, containsInAnyOrder(DayOfWeek.SUNDAY, DayOfWeek.FRIDAY))
database.updateSchedule(profile.schedule)
updated = database.getProfile(profile.id)!!
assertFalse(updated.schedule.enabled)
assertEquals(900, updated.schedule.start)
assertEquals(1700, updated.schedule.end)
assertThat("Contains correct default days", updated.schedule.daysEnabled, containsInAnyOrder(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY))
updated = database.updateProfile(profile.copy(schedule = profile.schedule.copy(enabled = true, start = 800, end = 1800, daysEnabled = setOf(DayOfWeek.SUNDAY, DayOfWeek.FRIDAY)))).profile
assertTrue(updated.schedule.enabled)
assertEquals(800, updated.schedule.start)
assertEquals(1800, updated.schedule.end)
assertThat("Contains updated days days", updated.schedule.daysEnabled, containsInAnyOrder(DayOfWeek.SUNDAY, DayOfWeek.FRIDAY))
updated = database.updateProfile(profile).profile
assertFalse(updated.schedule.enabled)
assertEquals(900, updated.schedule.start)
assertEquals(1700, updated.schedule.end)
assertThat("Contains correct default days", updated.schedule.daysEnabled, containsInAnyOrder(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY))
}
}
private val NotificationProfileDatabase.NotificationProfileChangeResult.profile: NotificationProfile
get() = (this as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile

View File

@@ -140,7 +140,7 @@ public class MockApplicationDependencyProvider implements ApplicationDependencie
@Override
public @NonNull DatabaseObserver provideDatabaseObserver() {
return null;
return mock(DatabaseObserver.class);
}
@Override

View File

@@ -0,0 +1,141 @@
package org.thoughtcrime.securesms.notifications.profiles
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.Test
import org.thoughtcrime.securesms.util.toMillis
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.util.TimeZone
class NotificationProfileScheduleTest {
private val sunday0am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 0, 0, 0)
private val sunday1am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 1, 0, 0)
private val sunday9am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 9, 0, 0)
private val sunday10pm: LocalDateTime = LocalDateTime.of(2021, 7, 4, 22, 0, 0)
private val monday0am: LocalDateTime = sunday0am.plusDays(1)
private val monday1am: LocalDateTime = sunday1am.plusDays(1)
private val monday9am: LocalDateTime = sunday9am.plusDays(1)
private val monday10pm: LocalDateTime = sunday10pm.plusDays(1)
private val tuesday1am: LocalDateTime = sunday1am.plusDays(2)
private val tuesday9am: LocalDateTime = sunday9am.plusDays(2)
private val tuesday10pm: LocalDateTime = sunday10pm.plusDays(2)
companion object {
@BeforeClass
@JvmStatic
fun setup() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
}
}
@Test
fun `when time is within enabled schedule 9am to 5pm then return true`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 900, end = 1700, daysEnabled = setOf(DayOfWeek.SUNDAY))
assertTrue(schedule.isCurrentlyActive(sunday9am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday9am.plusHours(1).toMillis()))
}
@Test
fun `when time is outside enabled schedule 9am to 5pm then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 900, end = 1700, daysEnabled = setOf(DayOfWeek.SUNDAY))
assertFalse(schedule.isCurrentlyActive(sunday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(sunday10pm.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday10pm.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday9am.toMillis()))
}
@Test
fun `when time is inside enabled with day wrapping schedule 10pm to 2am then return true`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 2100, end = 200, daysEnabled = setOf(DayOfWeek.MONDAY))
assertTrue(schedule.isCurrentlyActive(monday10pm.toMillis()))
assertTrue(schedule.isCurrentlyActive(tuesday1am.toMillis()))
}
@Test
fun `when time is outside enabled with day wrapping schedule 10pm to 2am then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 2100, end = 200, daysEnabled = setOf(DayOfWeek.MONDAY))
assertFalse(schedule.isCurrentlyActive(sunday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(sunday10pm.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday10pm.toMillis()))
}
@Test
fun `when time is inside enabled schedule 12am to 10am then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 0, end = 1000, daysEnabled = setOf(DayOfWeek.SUNDAY))
assertTrue(schedule.isCurrentlyActive(sunday0am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday1am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday9am.toMillis()))
}
@Test
fun `when time is inside enabled schedule 12am to 12am then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 0, end = 2400, daysEnabled = setOf(DayOfWeek.SUNDAY))
assertTrue(schedule.isCurrentlyActive(sunday0am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday1am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday9am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday10pm.toMillis()))
}
@Test
fun `when time is outside enabled schedule 12am to 12am then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 0, end = 2400, daysEnabled = setOf(DayOfWeek.SUNDAY))
assertFalse(schedule.isCurrentlyActive(monday0am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday10pm.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday10pm.toMillis()))
}
@Test
fun `when enabled schedule 12am to 12am for all days then return true`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = true, start = 0, end = 2400, daysEnabled = DayOfWeek.values().toSet())
assertTrue(schedule.isCurrentlyActive(sunday0am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday1am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday9am.toMillis()))
assertTrue(schedule.isCurrentlyActive(sunday10pm.toMillis()))
assertTrue(schedule.isCurrentlyActive(monday0am.toMillis()))
assertTrue(schedule.isCurrentlyActive(monday1am.toMillis()))
assertTrue(schedule.isCurrentlyActive(monday9am.toMillis()))
assertTrue(schedule.isCurrentlyActive(monday10pm.toMillis()))
assertTrue(schedule.isCurrentlyActive(tuesday1am.toMillis()))
assertTrue(schedule.isCurrentlyActive(tuesday9am.toMillis()))
assertTrue(schedule.isCurrentlyActive(tuesday10pm.toMillis()))
}
@Test
fun `when disabled schedule 12am to 12am for all days then return false`() {
val schedule = NotificationProfileSchedule(id = 1L, enabled = false, start = 0, end = 2400, daysEnabled = DayOfWeek.values().toSet())
assertFalse(schedule.isCurrentlyActive(sunday0am.toMillis()))
assertFalse(schedule.isCurrentlyActive(sunday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(sunday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(sunday10pm.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday0am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(monday10pm.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday1am.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday9am.toMillis()))
assertFalse(schedule.isCurrentlyActive(tuesday10pm.toMillis()))
}
}

View File

@@ -0,0 +1,141 @@
package org.thoughtcrime.securesms.notifications.profiles
import android.app.Application
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.nullValue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.thoughtcrime.securesms.SignalStoreRule
import org.thoughtcrime.securesms.keyvalue.NotificationProfileValues
import org.thoughtcrime.securesms.util.toMillis
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.time.ZoneId
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE, application = Application::class)
class NotificationProfilesTest {
private val sunday830am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 8, 30, 0)
private val sunday9am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 9, 0, 0)
private val sunday930am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 9, 30, 0)
private val utc: ZoneId = ZoneId.of("UTC")
private val first = NotificationProfile(
id = 1L,
"first",
"",
createdAt = 1000L,
schedule = NotificationProfileSchedule(1)
)
private val second = NotificationProfile(
id = 2L,
"second",
"",
createdAt = 2000L,
schedule = NotificationProfileSchedule(2)
)
@get:Rule
val signalStore: SignalStoreRule = SignalStoreRule()
@Test
fun `when no profiles then return null`() {
assertThat("no active profile", NotificationProfiles.getActiveProfile(emptyList(), 1000L, utc), nullValue())
}
@Test
fun `when no manually enabled or schedule profiles then return null`() {
val profiles = listOf(first, second)
assertThat("no active profile", NotificationProfiles.getActiveProfile(profiles, 3000L, utc), nullValue())
}
@Test
fun `when first is not enabled and second is manually enabled forever then return second`() {
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, second.id)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, Long.MAX_VALUE)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, 5000L)
val profiles = listOf(first, second)
assertThat("active profile is profile second", NotificationProfiles.getActiveProfile(profiles, 3000L, utc), `is`(profiles[1]))
}
@Test
fun `when first is scheduled and second is not manually enabled and now is within schedule return first`() {
val schedule = NotificationProfileSchedule(id = 3L, true, start = 700, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = schedule), second)
assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(), utc), `is`(profiles[0]))
}
@Test
fun `when first is scheduled and second is manually enabled forever within first's schedule then return second`() {
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, second.id)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, Long.MAX_VALUE)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis())
val schedule = NotificationProfileSchedule(id = 3L, true, start = 700, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = schedule), second)
assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(), utc), `is`(profiles[1]))
}
@Test
fun `when first is scheduled and second is manually enabled forever before first's schedule start then return first`() {
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, second.id)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, Long.MAX_VALUE)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis())
val schedule = NotificationProfileSchedule(id = 3L, true, start = 900, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = schedule), second)
assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, sunday930am.toMillis(), utc), `is`(profiles[0]))
}
@Test
fun `when first and second have overlapping schedules and second is created after first and now is within both then return second`() {
val firstSchedule = NotificationProfileSchedule(id = 3L, true, start = 700, daysEnabled = setOf(DayOfWeek.SUNDAY))
val secondSchedule = NotificationProfileSchedule(id = 4L, true, start = 800, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = firstSchedule), second.copy(schedule = secondSchedule))
assertThat("active profile is second", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(), utc), `is`(profiles[1]))
}
@Test
fun `when first and second have overlapping schedules and first is created before second and first is manually enabled within overlapping schedule then return first`() {
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, first.id)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, Long.MAX_VALUE)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis())
val firstSchedule = NotificationProfileSchedule(id = 3L, true, start = 700, daysEnabled = setOf(DayOfWeek.SUNDAY))
val secondSchedule = NotificationProfileSchedule(id = 4L, true, start = 700, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = firstSchedule), second.copy(schedule = secondSchedule))
assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(), utc), `is`(profiles[0]))
}
@Test
fun `when profile is manually enabled for set time after schedule end and now is after schedule end but before manual then return profile`() {
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, first.id)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, sunday930am.toMillis())
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis())
val schedule = NotificationProfileSchedule(id = 3L, true, start = 700, end = 845, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = schedule))
assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(), utc), `is`(profiles[0]))
}
@Test
fun `when profile is manually enabled for set time before schedule end and now is after manual but before schedule end then return null`() {
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, first.id)
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, sunday9am.toMillis())
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis())
val schedule = NotificationProfileSchedule(id = 3L, true, start = 700, end = 1000, daysEnabled = setOf(DayOfWeek.SUNDAY))
val profiles = listOf(first.copy(schedule = schedule))
assertThat("active profile is null", NotificationProfiles.getActiveProfile(profiles, sunday930am.toMillis(), utc), nullValue())
}
}

View File

@@ -2,24 +2,20 @@ package org.thoughtcrime.securesms.util;
import android.app.Application;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.thoughtcrime.securesms.SignalStoreRule;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.dependencies.MockApplicationDependencyProvider;
import org.thoughtcrime.securesms.keyvalue.AccountValues;
import org.thoughtcrime.securesms.keyvalue.KeyValueDataSet;
import org.thoughtcrime.securesms.keyvalue.KeyValueStore;
import org.thoughtcrime.securesms.keyvalue.MockKeyValuePersistentStorage;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import java.util.Arrays;
import java.util.Collection;
import kotlin.Unit;
import static junit.framework.TestCase.assertEquals;
@RunWith(ParameterizedRobolectricTestRunner.class)
@@ -46,17 +42,11 @@ public class SignalMeUtilText_parseE164FromLink {
});
}
@Before
public void setup() {
if (!ApplicationDependencies.isInitialized()) {
ApplicationDependencies.init(ApplicationProvider.getApplicationContext(), new MockApplicationDependencyProvider());
}
KeyValueDataSet dataSet = new KeyValueDataSet();
@Rule
public SignalStoreRule signalStore = new SignalStoreRule(dataSet -> {
dataSet.putString(AccountValues.KEY_E164, "+15555555555");
SignalStore.inject(new KeyValueStore(MockKeyValuePersistentStorage.withDataSet(dataSet)));
}
return Unit.INSTANCE;
});
public SignalMeUtilText_parseE164FromLink(String input, String output) {
this.input = input;