package net.pokeranalytics.android.unitTests.filter

import androidx.test.ext.junit.runners.AndroidJUnit4
import io.realm.RealmList
import net.pokeranalytics.android.components.BaseFilterInstrumentedUnitTest
import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*

@RunWith(AndroidJUnit4::class)
class SessionFilterInstrumentedUnitTest : BaseFilterInstrumentedUnitTest() {

    @Test
    fun testCashFilter() {

        val realm = this.mockRealm
        realm.beginTransaction()

        Session.testInstance(100.0, false, Date(), 1)
        Session.testInstance(100.0, true, Date(), 1)
        realm.commitTransaction()

        val sessions = Filter.queryOn<Session>(realm, Query(QueryCondition.IsCash))

        Assert.assertEquals(1, sessions.size)
        sessions[0]?.run {
            Assert.assertEquals(Session.Type.CASH_GAME.ordinal, (this).type)
        }
    }

    @Test
    fun testTournamentFilter() {

        val realm = this.mockRealm
        realm.beginTransaction()

        Session.testInstance(100.0, false, Date(), 1)
        Session.testInstance(100.0, true, Date(), 1)
        realm.commitTransaction()

        val sessions = Filter.queryOn<Session>(realm, Query(QueryCondition.IsTournament))

        Assert.assertEquals(1, sessions.size)
        sessions[0]?.run {
            Assert.assertEquals(Session.Type.TOURNAMENT.ordinal, (this).type)
        }
    }

    @Test
    fun testLiveFilter() {

        val realm = this.mockRealm

        realm.beginTransaction()
        val b1 = realm.createObject(Bankroll::class.java, "1")
        val b2 = realm.createObject(Bankroll::class.java, "2")
        b1.live = true
        b2.live = false

        Session.testInstance(100.0, false, Date(), 1, b1)
        Session.testInstance(100.0, true, Date(), 1, b2)
        realm.commitTransaction()

        val sessions = Filter.queryOn<Session>(realm, Query(QueryCondition.IsLive))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).bankroll?.run {
            Assert.assertEquals(true, this.live)
        }
    }

    @Test
    fun testOnlineFilter() {

        val realm = this.mockRealm
        realm.beginTransaction()
        val b1 = realm.createObject(Bankroll::class.java, "1")
        val b2 = realm.createObject(Bankroll::class.java, "2")
        b1.live = false
        b2.live = true

        Session.testInstance(100.0, false, Date(), 1, b1)
        Session.testInstance(100.0, true, Date(), 1, b2)
        realm.commitTransaction()

        val sessions = Filter.queryOn<Session>(realm, Query(QueryCondition.IsOnline))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).bankroll?.run {
            Assert.assertEquals(false, this.live)
        }
    }

    @Test
    fun testBankrollFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val b1 = realm.createObject(Bankroll::class.java, "1")
        val b2 = realm.createObject(Bankroll::class.java, "2")
        b1.live = false
        b2.live = true
        Session.testInstance(bankroll = b1)
        Session.testInstance(bankroll = b2)
        realm.commitTransaction()

        val filter = QueryCondition.AnyBankroll()
        val filterElementRow = QueryCondition.AnyBankroll().apply { setObject(b1) }
        filterElementRow.filterSectionRow = FilterSectionRow.Bankroll
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).bankroll?.run {
            Assert.assertEquals(b1.id, this.id)
        }
    }

    @Test
    fun testMultipleBankrollFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val b1 = realm.createObject(Bankroll::class.java, "1")
        val b2 = realm.createObject(Bankroll::class.java, "2")
        val b3 = realm.createObject(Bankroll::class.java, "3")
        Session.testInstance(bankroll = b1)
        Session.testInstance(bankroll = b2)
        Session.testInstance(bankroll = b3)
        Session.testInstance(bankroll = b1)
        Session.testInstance(bankroll = b2)
        Session.testInstance(bankroll = b3)
        Session.testInstance(bankroll = b1)
        Session.testInstance(bankroll = b2)
        Session.testInstance(bankroll = b3)
        realm.commitTransaction()

        val filter = QueryCondition.AnyBankroll()
        val filterElementRow = QueryCondition.AnyBankroll().apply { setObject(b1) }
        filterElementRow.filterSectionRow = FilterSectionRow.Bankroll

        val filterElementRow2 = QueryCondition.AnyBankroll().apply { setObject(b2) }
        filterElementRow2.filterSectionRow = FilterSectionRow.Bankroll
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(6, sessions.size)

        val result = arrayListOf(b1.id, b2.id)

        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).bankroll?.id))
        }
    }

    @Test
    fun testGameFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val g1 = realm.createObject(Game::class.java, "1")
        val g2 = realm.createObject(Game::class.java, "2")
        Session.testInstance(game = g1)
        Session.testInstance(game = g2)
        realm.commitTransaction()

        val anyGame = QueryCondition.AnyGame(g2)
        val fc = FilterCondition(filterElementRows = arrayListOf(anyGame))
        val sessions = Filter.queryOn<Session>(realm, Query(fc.queryCondition))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).game?.run {
            Assert.assertEquals(g2.id, this.id)
        }
    }

    @Test
    fun testMultipleGameFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val g1 = realm.createObject(Game::class.java, "1")
        val g2 = realm.createObject(Game::class.java, "2")
        val g3 = realm.createObject(Game::class.java, "3")
        Session.testInstance(game = g1)
        Session.testInstance(game = g2)
        Session.testInstance(game = g3)
        Session.testInstance(game = g1)
        Session.testInstance(game = g2)
        Session.testInstance(game = g3)
        Session.testInstance(game = g1)
        Session.testInstance(game = g2)
        Session.testInstance(game = g3)
        realm.commitTransaction()

        val filterElementRow = QueryCondition.AnyGame().apply { setObject(g2) }
        filterElementRow.filterSectionRow = FilterSectionRow.Game
        val filterElementRow2 = QueryCondition.AnyGame().apply { setObject(g3) }
        filterElementRow2.filterSectionRow = FilterSectionRow.Game
        val filterCondition = FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2))
        val queryCondition = filterCondition.queryCondition
        val sessions = Filter.queryOn<Session>(realm, Query(queryCondition))

        Assert.assertEquals(6, sessions.size)

        val result = arrayListOf(g2.id, g3.id)

        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).game?.id))
        }
    }

    @Test
    fun testLocationFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val l1 = realm.createObject(Location::class.java, "1")
        val l2 = realm.createObject(Location::class.java, "2")
        Session.testInstance(location = l1)
        Session.testInstance(location = l2)
        realm.commitTransaction()

        val filter = QueryCondition.AnyLocation()
        val filterElementRow = QueryCondition.AnyLocation().apply { setObject(l1) }
        filterElementRow.filterSectionRow = FilterSectionRow.Location
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).location?.run {
            Assert.assertEquals(l1.id, this.id)
        }
    }

    @Test
    fun testMultipleLocationFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val l1 = realm.createObject(Location::class.java, "1")
        val l2 = realm.createObject(Location::class.java, "2")
        val l3 = realm.createObject(Location::class.java, "3")
        Session.testInstance(location = l1)
        Session.testInstance(location = l2)
        Session.testInstance(location = l3)
        Session.testInstance(location = l1)
        Session.testInstance(location = l2)
        Session.testInstance(location = l3)
        Session.testInstance(location = l1)
        Session.testInstance(location = l2)
        Session.testInstance(location = l3)
        realm.commitTransaction()

        val filter = QueryCondition.AnyLocation()

        val filterElementRow = QueryCondition.AnyLocation().apply { setObject(l1) }
        filterElementRow.filterSectionRow = FilterSectionRow.Location
        val filterElementRow2 = QueryCondition.AnyLocation().apply { setObject(l3) }
        filterElementRow2.filterSectionRow = FilterSectionRow.Location

        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(6, sessions.size)

        val result = arrayListOf(l1.id, l3.id)

        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).location?.id))
        }
    }

    @Test
    fun testTournamentNameFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val t1 = realm.createObject(TournamentName::class.java, "1")
        val t2 = realm.createObject(TournamentName::class.java, "2")
        Session.testInstance(tournamentName = t1)
        Session.testInstance(tournamentName = t2)
        realm.commitTransaction()

        val filter = QueryCondition.AnyTournamentName()

        val filterElementRow = QueryCondition.AnyTournamentName().apply { setObject(t1) }
        filterElementRow.filterSectionRow = FilterSectionRow.TournamentName
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).tournamentName?.run {
            Assert.assertEquals(t1.id, this.id)
        }
    }

    @Test
    fun testMultipleTournamentNameFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val t1 = realm.createObject(TournamentName::class.java, "1")
        val t2 = realm.createObject(TournamentName::class.java, "2")
        val t3 = realm.createObject(TournamentName::class.java, "3")
        Session.testInstance(tournamentName = t1)
        Session.testInstance(tournamentName = t2)
        Session.testInstance(tournamentName = t3)
        Session.testInstance(tournamentName = t1)
        Session.testInstance(tournamentName = t2)
        Session.testInstance(tournamentName = t3)
        Session.testInstance(tournamentName = t1)
        Session.testInstance(tournamentName = t2)
        Session.testInstance(tournamentName = t3)
        realm.commitTransaction()

        val filter = QueryCondition.AnyTournamentName()
        val filterElementRow = QueryCondition.AnyTournamentName().apply { setObject(t1) }
        filterElementRow.filterSectionRow = FilterSectionRow.TournamentName
        val filterElementRow2 = QueryCondition.AnyTournamentName().apply { setObject(t2) }
        filterElementRow.filterSectionRow = FilterSectionRow.TournamentName
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(6, sessions.size)

        val result = arrayListOf(t1.id, t2.id)

        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).tournamentName?.id))
        }
    }

    @Test
    fun testAllTournamentFeatureFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val t1 = realm.createObject(TournamentFeature::class.java, "1")
        val t2 = realm.createObject(TournamentFeature::class.java, "2")
        val t3 = realm.createObject(TournamentFeature::class.java, "3")
        val t4 = realm.createObject(TournamentFeature::class.java, "4")
        Session.testInstance(tournamentFeatures = RealmList(t1,t2))
        Session.testInstance(tournamentFeatures = RealmList(t2,t3))
        Session.testInstance(tournamentFeatures = RealmList(t3,t4))
        val s = Session.testInstance(tournamentFeatures = RealmList(t1,t2,t3,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t3))
        Session.testInstance(tournamentFeatures = RealmList(t2,t4, t3))
        Session.testInstance(tournamentFeatures = RealmList(t1))
        realm.commitTransaction()

        val filter = QueryCondition.AllTournamentFeature()
        val filterElementRow = QueryCondition.AllTournamentFeature().apply { setObject(t1) }
        filterElementRow.filterSectionRow = FilterSectionRow.TournamentFeature
        val filterElementRow2 = QueryCondition.AllTournamentFeature().apply { setObject(t2) }
        filterElementRow2.filterSectionRow = FilterSectionRow.TournamentFeature
        val filterElementRow3 = QueryCondition.AllTournamentFeature().apply { setObject(t4) }
        filterElementRow3.filterSectionRow = FilterSectionRow.TournamentFeature
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2, filterElementRow3)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(1, sessions.size)
        (sessions[0] as Session).run {
            Assert.assertEquals(s.id, this.id)
        }
    }

    @Test
    fun testAnyTournamentFeatureFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val t1 = realm.createObject(TournamentFeature::class.java, "1")
        val t2 = realm.createObject(TournamentFeature::class.java, "2")
        val t3 = realm.createObject(TournamentFeature::class.java, "3")
        val t4 = realm.createObject(TournamentFeature::class.java, "4")
        Session.testInstance(tournamentFeatures = RealmList(t1,t2))
        Session.testInstance(tournamentFeatures = RealmList(t2,t3))
        Session.testInstance(tournamentFeatures = RealmList(t3,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t2,t3,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t3))
        Session.testInstance(tournamentFeatures = RealmList(t2,t4, t3))
        Session.testInstance(tournamentFeatures = RealmList(t1))
        realm.commitTransaction()

        val filter = QueryCondition.AnyTournamentFeature()
        val filterElementRow = QueryCondition.AnyTournamentFeature().apply { setObject(t1) }
        filterElementRow.filterSectionRow = FilterSectionRow.TournamentFeature
        val filterElementRow2 = QueryCondition.AnyTournamentFeature().apply { setObject(t2) }
        filterElementRow2.filterSectionRow = FilterSectionRow.TournamentFeature
        val filterElementRow3 = QueryCondition.AnyTournamentFeature().apply { setObject(t3) }
        filterElementRow3.filterSectionRow = FilterSectionRow.TournamentFeature
        val filterElementRow4 = QueryCondition.AnyTournamentFeature().apply { setObject(t4) }
        filterElementRow4.filterSectionRow = FilterSectionRow.TournamentFeature
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2, filterElementRow3, filterElementRow4)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(8, sessions.size)
    }

    @Test
    fun testSingleAnyTournamentFeatureFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val t1 = realm.createObject(TournamentFeature::class.java, "1")
        val t2 = realm.createObject(TournamentFeature::class.java, "2")
        val t3 = realm.createObject(TournamentFeature::class.java, "3")
        val t4 = realm.createObject(TournamentFeature::class.java, "4")
        val s1 = Session.testInstance(tournamentFeatures = RealmList(t1,t2))
        val s2 = Session.testInstance(tournamentFeatures = RealmList(t2,t3))
        Session.testInstance(tournamentFeatures = RealmList(t3,t4))
        val s3 = Session.testInstance(tournamentFeatures = RealmList(t1,t2,t3,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t4))
        Session.testInstance(tournamentFeatures = RealmList(t1,t3))
        val s4 = Session.testInstance(tournamentFeatures = RealmList(t2,t4, t3))
        Session.testInstance(tournamentFeatures = RealmList(t1))
        realm.commitTransaction()

        val filter = QueryCondition.AnyTournamentFeature()
        val filterElementRow = QueryCondition.AnyTournamentFeature().apply { setObject(t2) }
        filterElementRow.filterSectionRow = FilterSectionRow.TournamentFeature
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        val result = arrayListOf(s1.id, s2.id, s3.id, s4.id)

        Assert.assertEquals(4, sessions.size)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }
    }

    @Test
    fun testTableSizeFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val s1 = Session.testInstance(tableSize = 2)
        val s2 = Session.testInstance(tableSize = 4)
        Session.testInstance(tableSize = 9)
        Session.testInstance(tableSize = 10)
        realm.commitTransaction()

        val filter = QueryCondition.AnyTableSize()
        val filterElementRow = QueryCondition.AnyTableSize().apply { listOfValues = arrayListOf(2) }
        filterElementRow.filterSectionRow = FilterSectionRow.TableSize
        val filterElementRow2 = QueryCondition.AnyTableSize().apply { listOfValues = arrayListOf(4) }
        filterElementRow.filterSectionRow = FilterSectionRow.TableSize
        filter.updateValueBy(FilterCondition(filterElementRows = arrayListOf(filterElementRow, filterElementRow2)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(2, sessions.size)

        val result = arrayListOf(s1.id, s2.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }
    }

    @Test
    fun testMoreThanNetResultFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        Session.testInstance(netResult = 200.0)
        val s1 = Session.testInstance(netResult = 500.0)
        Session.testInstance(netResult = 50.0)
        val s2 = Session.testInstance(netResult = 570.0)
        realm.commitTransaction()

        val filter = QueryCondition.NetAmountWon()
        val filterElementRow = QueryCondition.more<QueryCondition.NetAmountWon>().apply { listOfValues = arrayListOf(204.0) }
        filterElementRow.filterSectionRow = FilterSectionRow.Value
        filter.updateValueBy(FilterCondition(arrayListOf(filterElementRow)))

        val sessions = Filter.queryOn<Session>(realm, Query(filterElementRow))

        Assert.assertEquals(2, sessions.size)

        val result = arrayListOf(s1.id, s2.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }
    }

    @Test
    fun testLessThanNetResultFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val s1 = Session.testInstance(netResult = 200.0)
        val s2 = Session.testInstance(netResult = 500.0)
        val s3 = Session.testInstance(netResult = 50.0)
        Session.testInstance(netResult = 570.0)
        realm.commitTransaction()

        val filter = QueryCondition.NetAmountWon()
        val filterElementRow = QueryCondition.less<QueryCondition.NetAmountWon>().apply { listOfValues = arrayListOf(540.0) }
        filterElementRow.filterSectionRow = FilterSectionRow.Value
        filter.updateValueBy(FilterCondition(arrayListOf(filterElementRow)))

        val sessions = Filter.queryOn<Session>(realm, Query(filter))

        Assert.assertEquals(3, sessions.size)

        val result = arrayListOf(s1.id, s2.id, s3.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }
    }

    @Test
    fun testNetResultFilter() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val s1 = Session.testInstance(netResult = 200.0)
        Session.testInstance(netResult = 500.0)
        Session.testInstance(netResult = 50.0)
        Session.testInstance(netResult = 570.0)
        realm.commitTransaction()

        val filterMore = QueryCondition.NetAmountWon()
        val filterElementRow = QueryCondition.more<QueryCondition.NetAmountWon>().apply { listOfValues = arrayListOf(199.0) }
        filterElementRow.filterSectionRow = FilterSectionRow.Value
        filterMore.updateValueBy(FilterCondition(arrayListOf(filterElementRow)))

        val filterLess = QueryCondition.NetAmountWon()
        val filterElementRow2 = QueryCondition.less<QueryCondition.NetAmountWon>().apply { listOfValues = arrayListOf(400.0) }
        filterElementRow2.filterSectionRow = FilterSectionRow.Value
        filterLess.updateValueBy(FilterCondition(arrayListOf(filterElementRow2)))

        val sessions = Filter.queryOn<Session>(realm, Query(filterMore, filterLess))

        Assert.assertEquals(1, sessions.size)

        val result = arrayListOf(s1.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }
    }

    @Test
    fun testNumberOfRebuys() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val s1 = Session.testInstance(netResult = 200.0, isTournament = true)
        s1.result!!.buyin = 50.0
        s1.tournamentEntryFee = 10.0
        val s2 = Session.testInstance(netResult = 50.0, isTournament = true)
        s2.result!!.buyin = 10.0
        s2.tournamentEntryFee = 10.0


        val s3 = Session.testInstance(netResult = 500.0)
        s3.cgBigBlind = 2.0
        s3.result!!.buyin = 1000.0

        val s4 = Session.testInstance(netResult = 570.0)
        s4.cgBigBlind = 5.0
        s4.result!!.buyin = 200.0
        realm.commitTransaction()

        val filterMore = QueryCondition.NumberOfRebuy(QueryCondition.Operator.MORE, 4.0)
        val sessions = Filter.queryOn<Session>(realm, Query(filterMore))

        Assert.assertEquals(2, sessions.size)

        val result = arrayListOf(s1.id, s3.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }
    }

    @Test
    fun testTournamentFinalPosition() {
        val realm = this.mockRealm
        realm.beginTransaction()
        val s1 = Session.testInstance(netResult = 200.0, isTournament = true)
        s1.result!!.tournamentFinalPosition = 5

        val s2 = Session.testInstance(netResult = 50.0, isTournament = true)
        s2.result!!.tournamentFinalPosition = 15

        val s3 = Session.testInstance(netResult = 500.0, isTournament = true)
        s3.result!!.tournamentFinalPosition = 2

        val s4 = Session.testInstance(netResult = 570.0, isTournament = true)
        s4.result!!.tournamentFinalPosition = 1
        realm.commitTransaction()

        val filterLess = QueryCondition.TournamentFinalPosition(QueryCondition.Operator.LESS, finalPosition = 1)
        var sessions = Filter.queryOn<Session>(realm, Query(filterLess))

        Assert.assertEquals(1, sessions.size)

        var result = arrayListOf(s4.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }


        val filterMore = QueryCondition.TournamentFinalPosition(QueryCondition.Operator.MORE, finalPosition = 10)
        sessions = Filter.queryOn<Session>(realm, Query(filterMore))

        Assert.assertEquals(1, sessions.size)

        result = arrayListOf(s2.id)
        sessions.forEach {
            Assert.assertTrue(result.contains((it as Session).id))
        }

    }
}