All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.comhix.database.dao.test.MockQuery.kt Maven / Gradle / Ivy

package de.comhix.database.dao.test

import com.google.common.collect.Lists
import de.comhix.database.dao.Query
import de.comhix.database.objects.QueryResult

/**
 * @author Benjamin Beeker
 */
class MockQuery @JvmOverloads constructor(private val data: Collection = Lists.newArrayList()) : Query() {
    constructor(vararg data: Type) : this(Lists.newArrayList(*data))

    override fun  with(field: String?, operation: Operation, value: AllowedValueType): Query {
        return this
    }

    override fun limit(limit: Int): Query {
        return this
    }

    override fun skip(skip: Int): Query {
        return this
    }

    override fun order(field: String?): Query {
        return this
    }

    override suspend fun query(): QueryResult {
        return QueryResult(Lists.newArrayList(data))
    }

    override suspend fun find(): Type? {
        return if (data.isEmpty()) null else data.iterator().next()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy