forked from orgzly-revived/orgzly-android-revived
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Un-parameterize three time-sensitive tests
This means the argument to the RetryTestRule is no longer in use, so remove it.
- Loading branch information
Showing
3 changed files
with
93 additions
and
20 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
90 changes: 90 additions & 0 deletions
90
app/src/androidTest/java/com/orgzly/android/query/TimeSensitiveQueryTest.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,90 @@ | ||
package com.orgzly.android.query | ||
|
||
import androidx.test.espresso.matcher.ViewMatchers | ||
import com.orgzly.android.OrgzlyTest | ||
import com.orgzly.android.query.sql.SqliteQueryBuilder | ||
import com.orgzly.android.query.user.DottedQueryParser | ||
import org.hamcrest.Matchers | ||
import org.junit.Test | ||
import java.util.Calendar | ||
|
||
/** | ||
* Parameterization works poorly for these cases, because when there are many parameters, | ||
* there may be a too long delay between parameter creation and test run, so that the | ||
* timestamp is too old when the test is run. | ||
*/ | ||
class TimeSensitiveQueryTest : OrgzlyTest() { | ||
@Test | ||
fun testScheduledWithinHours1() { | ||
// Parse query | ||
val queryString = "s.le.2h" | ||
val expectedSqlSelection = "((scheduled_is_active = 1 AND scheduled_time_timestamp != 0 AND scheduled_time_timestamp < " + TimeUtils.timeFromNow( | ||
Calendar.HOUR_OF_DAY, 2+1) + "))" | ||
val parser = DottedQueryParser() | ||
val query = parser.parse(queryString) | ||
|
||
// Build SQL | ||
val sqlBuilder = SqliteQueryBuilder(context) | ||
val sqlQuery = sqlBuilder.build(query) | ||
|
||
// Build query | ||
val actualSqlSelection = sqlQuery.selection | ||
|
||
expectedSqlSelection.let { | ||
ViewMatchers.assertThat( | ||
queryString, | ||
actualSqlSelection, | ||
Matchers.`is`(expectedSqlSelection) | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testScheduledWithinHours2() { | ||
// Parse query | ||
val queryString = "s.le.+2h" | ||
val expectedSqlSelection = "((scheduled_is_active = 1 AND scheduled_time_timestamp != 0 AND scheduled_time_timestamp < " + TimeUtils.timeFromNow( | ||
Calendar.HOUR_OF_DAY, 2+1) + "))" | ||
val parser = DottedQueryParser() | ||
val query = parser.parse(queryString) | ||
|
||
// Build SQL | ||
val sqlBuilder = SqliteQueryBuilder(context) | ||
val sqlQuery = sqlBuilder.build(query) | ||
|
||
// Build query | ||
val actualSqlSelection = sqlQuery.selection | ||
|
||
expectedSqlSelection.let { | ||
ViewMatchers.assertThat( | ||
queryString, | ||
actualSqlSelection, | ||
Matchers.`is`(expectedSqlSelection) | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testClosedRecently() { | ||
// Parse query | ||
val queryString = "c.gt.-1h" | ||
val expectedSqlSelection = "((closed_time_timestamp != 0 AND ${TimeUtils.timeFromNow(Calendar.HOUR_OF_DAY, 0)} <= closed_time_timestamp))" | ||
val parser = DottedQueryParser() | ||
val query = parser.parse(queryString) | ||
|
||
// Build SQL | ||
val sqlBuilder = SqliteQueryBuilder(context) | ||
val sqlQuery = sqlBuilder.build(query) | ||
|
||
// Build query | ||
val actualSqlSelection = sqlQuery.selection | ||
|
||
expectedSqlSelection.let { | ||
ViewMatchers.assertThat( | ||
queryString, | ||
actualSqlSelection, | ||
Matchers.`is`(expectedSqlSelection) | ||
) | ||
} | ||
} | ||
} |