-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
163 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 0 additions & 84 deletions
84
app/src/androidTest/java/spam/blocker/util/RecurringTest.kt
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
app/src/androidTest/java/spam/blocker/util/ScheduleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package spam.blocker.util | ||
|
||
import io.mockk.every | ||
import io.mockk.mockkObject | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import spam.blocker.service.bot.Daily | ||
import spam.blocker.service.bot.Time | ||
import spam.blocker.service.bot.Weekly | ||
import java.time.DayOfWeek.THURSDAY | ||
import java.time.DayOfWeek.TUESDAY | ||
import java.time.DayOfWeek.WEDNESDAY | ||
import java.time.Duration | ||
import java.time.LocalDateTime | ||
|
||
class ScheduleTest { | ||
|
||
@Test | ||
fun timeIsValid() { | ||
assertEquals(Time(0, 0).isValid(), true) | ||
assertEquals(Time(23, 59).isValid(), true) | ||
assertEquals(Time(-1, 0).isValid(), false) | ||
assertEquals(Time(24, 0).isValid(), false) | ||
assertEquals(Time(0, 60).isValid(), false) | ||
assertEquals(Time(0, 60).isValid(), false) | ||
} | ||
|
||
private fun setNow(now: LocalDateTime) { | ||
every { LocalDateTimeMockk.now() } returns now | ||
} | ||
|
||
@Test | ||
fun daily() { | ||
mockkObject(LocalDateTimeMockk) | ||
|
||
var dur: Duration | ||
|
||
// now: <2000-1-1 0:0>, time: <1:0> -> dur: 1 hour | ||
setNow(LocalDateTime.of(2000, 1, 1, 0, 0, 0)) | ||
dur = Daily(Time(1, 0)).nextOccurrence() | ||
assertEquals("same day", 1 * 3600 * 1000, dur.toMillis()) | ||
|
||
// now: <2000-1-1 0:0>, time: <0:0> -> dur: 24 hours | ||
setNow(LocalDateTime.of(2000, 1, 1, 0, 0, 0)) | ||
dur = Daily(Time(0, 0)).nextOccurrence() | ||
assertEquals("next day", 24 * 3600 * 1000, dur.toMillis()) | ||
|
||
// now: <2023-12-31 10:0>, time: <0:0> -> dur: 14 hours | ||
setNow(LocalDateTime.of(2023, 12, 31, 10, 0, 0)) | ||
dur = Daily(Time(0, 0)).nextOccurrence() | ||
assertEquals("cross year", 14 * 3600 * 1000, dur.toMillis()) | ||
} | ||
|
||
@Test | ||
fun weekly() { | ||
mockkObject(LocalDateTimeMockk) | ||
|
||
var dur: Duration | ||
val hour = (1 * 3600 * 1000).toLong() | ||
val day = (24 * hour).toLong() | ||
|
||
// now: <2024-10-1 Tuesday 0:0:0>, weekdays: [Tuesday], time: <1:0:0> -> dur: 1 hour | ||
setNow(LocalDateTime.parse("2024-10-01T00:00:00")) | ||
dur = Weekly(listOf(TUESDAY), Time(1, 0)).nextOccurrence() | ||
assertEquals("same day", 1 * hour, dur.toMillis()) | ||
|
||
// now: <2024-10-1 Tuesday 0:0:0>, weekdays: [Tuesday, Wednesday], time: <0:0:0> -> dur: 1 day | ||
setNow(LocalDateTime.parse("2024-10-01T00:00:00")) | ||
dur = Weekly(listOf(TUESDAY, WEDNESDAY), Time(0, 0)).nextOccurrence() | ||
assertEquals("next day", 1 * day, dur.toMillis()) | ||
|
||
// now: <2024-10-1 Tuesday 0:0:0>, weekdays: [Tuesday], time: <0:0:0> -> dur: 7 days | ||
setNow(LocalDateTime.parse("2024-10-01T00:00:00")) | ||
dur = Weekly(listOf(TUESDAY), Time(0, 0)).nextOccurrence() | ||
assertEquals("next week", 7 * day, dur.toMillis()) | ||
|
||
// now: <2024-10-31 Thursday 0:0:0>, weekdays: [Thursday], time: <0:0:0> -> dur: 7 days | ||
setNow(LocalDateTime.parse("2024-10-31T00:00:00")) | ||
dur = Weekly(listOf(THURSDAY), Time(0, 0)).nextOccurrence() | ||
assertEquals("cross month", 7 * day, dur.toMillis()) | ||
|
||
// now: <2024-12-31 Tuesday 0:0:0>, weekdays: [Tuesday], time: <0:0:0> -> dur: 7 days | ||
setNow(LocalDateTime.parse("2024-12-31T00:00:00")) | ||
dur = Weekly(listOf(TUESDAY), Time(0, 0)).nextOccurrence() | ||
assertEquals("cross year", 7 * day, dur.toMillis()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Breaking: | ||
- no longer support "export backup as json format" | ||
- New permissions: | ||
- INTERNET: for downloading spam database, you can [disable it](https://github.com/aj3423/SpamBlocker/issues/147) if you don't use this feature. | ||
- MANAGE_EXTERNAL_STORAGE(Android 11+) or READ/WRITE_EXTERNAL_STORAGE(Android 10), for automated file operations, such as "backup" or "import .csv". | ||
|
||
New: | ||
- Spam Database. It's compatible with any public data sources, such as the [FTC - DNC](ftc.gov/policy-notices/open-government/data-sets/do-not-call-data) | ||
- Automated workflow. Use cases: | ||
- Download spam numbers from public database everyday. | ||
- Clean up expired numbers in database. | ||
- Auto backup, auto switch configuration, auto import csv/xml, etc. | ||
- Regex contact mode. The regex will match the contact name instead of the phone number | ||
- language support: pt-rBR, ja | ||
|
||
Fix: | ||
- The history cleanup task is not applied after backup-import |