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

org.jetbrains.spek.engine.lifecycle.LifecycleManager.kt Maven / Gradle / Ivy

There is a newer version: 1.1.5
Show newest version
package org.jetbrains.spek.engine.lifecycle

import org.jetbrains.spek.api.lifecycle.ActionScope
import org.jetbrains.spek.api.lifecycle.GroupScope
import org.jetbrains.spek.api.lifecycle.LifecycleListener
import org.jetbrains.spek.api.lifecycle.TestScope
import java.util.ArrayList

/**
 * @author Ranie Jade Ramiso
 */
class LifecycleManager {
    private val listeners = ArrayList()

    fun addListener(listener: LifecycleListener) {
        if (listeners.contains(listener)) {
            throw IllegalArgumentException("You can only register a listener once.")

        }

        listeners.add(0, listener)
    }

    fun removeListener(listener: LifecycleListener) {
        listeners.remove(listener)
    }

    fun beforeExecuteTest(test: TestScope) {
        listeners.forEach { it.beforeExecuteTest(test) }
    }

    fun afterExecuteTest(test: TestScope) {
        listeners.forEach { it.afterExecuteTest(test) }
    }

    fun beforeExecuteGroup(group: GroupScope) {
        listeners.forEach { it.beforeExecuteGroup(group) }
    }

    fun afterExecuteGroup(group: GroupScope) {
        listeners.forEach { it.afterExecuteGroup(group) }
    }

    fun beforeExecuteAction(action: ActionScope) {
        listeners.forEach { it.beforeExecuteAction(action) }
    }

    fun afterExecuteAction(action: ActionScope) {
        listeners.forEach { it.afterExecuteAction(action) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy