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

io.cucumber.scala.ScalaDefaultDataTableEntryTransformerDefinition.scala Maven / Gradle / Ivy

There is a newer version: 8.24.0
Show newest version
package io.cucumber.scala

import java.lang.reflect.Type
import java.util.{Map => JavaMap}

import io.cucumber.core.backend.{
  DefaultDataTableEntryTransformerDefinition,
  ScenarioScoped
}
import io.cucumber.datatable.{
  TableCellByTypeTransformer,
  TableEntryByTypeTransformer
}

import scala.jdk.CollectionConverters._

trait ScalaDefaultDataTableEntryTransformerDefinition
    extends DefaultDataTableEntryTransformerDefinition
    with AbstractDatatableElementTransformerDefinition {

  val details: ScalaDefaultDataTableEntryTransformerDetails

  override val emptyPatterns: Seq[String] = details.emptyPatterns

  override val location: StackTraceElement = new Exception().getStackTrace()(3)

  override val tableEntryByTypeTransformer: TableEntryByTypeTransformer = (
      fromValue: JavaMap[String, String],
      toValueType: Type,
      _: TableCellByTypeTransformer
  ) => {
    replaceEmptyPatternsWithEmptyString(fromValue.asScala.toMap)
      .map(details.body.apply(_, toValueType))
      .get
  }

  override val headersToProperties: Boolean = true

}

object ScalaDefaultDataTableEntryTransformerDefinition {

  def apply(
      details: ScalaDefaultDataTableEntryTransformerDetails,
      scenarioScoped: Boolean
  ): ScalaDefaultDataTableEntryTransformerDefinition = {
    if (scenarioScoped) {
      new ScalaScenarioScopedDataTableEntryTransformerDefinition(details)
    } else {
      new ScalaGlobalDataTableEntryTransformerDefinition(details)
    }
  }

}

class ScalaScenarioScopedDataTableEntryTransformerDefinition(
    override val details: ScalaDefaultDataTableEntryTransformerDetails
) extends ScalaDefaultDataTableEntryTransformerDefinition
    with ScenarioScoped {}

class ScalaGlobalDataTableEntryTransformerDefinition(
    override val details: ScalaDefaultDataTableEntryTransformerDetails
) extends ScalaDefaultDataTableEntryTransformerDefinition {}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy