Commit 94cb76a3 authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: splitted TreeParserEvent matchers into several objects to...

Integrated Pipeline: splitted TreeParserEvent matchers into several objects to avoid property name clashes with finer-grained imports
parent 2279098b
......@@ -2,7 +2,7 @@ package eu.nomad_lab.integrated_pipeline_tests
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.integrated_pipeline.{ EventListener, ParsingTaskGenerator, TreeParser }
import eu.nomad_lab.integrated_pipeline_tests.matchers.{ TreeParserEventMatchers, FileParsingTaskMatchers }
import eu.nomad_lab.integrated_pipeline_tests.matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.mockito.invocation.InvocationOnMock
......@@ -97,7 +97,7 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
}
"notify the provided EventListener when receiving a new file tree scan task" in {
import TreeParserEventMatchers._
import MatcherTreeParserEventStart._
val f = createFixture()
f.treeParser.processSignal(sampleTreeTask)
val captor = argsCaptor()
......@@ -126,7 +126,7 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
}
"notify the provided EventListener for each emitted candidate calculation" in {
import TreeParserEventMatchers._
import MatcherTreeParserEventCandidate._
val f = createFixture()
(1 to 3).map { _ => f.treeParser.getNextSignalToEmit() }
val captor = argsCaptor()
......@@ -167,7 +167,7 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
}
"notify the provided EventListener when emitting the end tree signal" in {
import TreeParserEventMatchers._
import MatcherTreeParserEventEnd._
val f = createFixture()
f.treeParser.getNextSignalToEmit()
val captor = argsCaptor()
......@@ -191,14 +191,14 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
def createFixture = () => taskReceivedWillCreateScanError()
"send a notification to the event listener" in {
import TreeParserEventMatchers._
import MatcherTreeParserEventScanError._
val f = createFixture()
f.treeParser.getNextSignalToEmit()
val captor = argsCaptor()
verify(f.events, Mockito.atLeast(1)).processEvent(any(), captor.capture())
val events = captor.getAllValues.asScala.collect { case x: TreeParserEventScanError => x }
events should have size 1
events.head should have(errorMessage("failing", "test case"), errorRelativePath("nullPointer"))
events.head should have(errorMessage("failing", "test case"), relativePath("nullPointer"))
}
}
}
......
......@@ -6,62 +6,6 @@ import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult
import org.scalatest.matchers.HavePropertyMatcher
object TreeParserEventMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[TreeParserEvent, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "tree base path",
expected = expectedValue,
test = (x: TreeParserEvent) => x.treeTask.treeBasePath
)
def basePath(expectedValue: String): HavePropertyMatcher[TreeParserEvent, Path] =
basePath(Paths.get(expectedValue))
def relativePath(expectedValue: Path): HavePropertyMatcher[TreeParserEventCandidate, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: TreeParserEventCandidate) => x.relativePath
)
def relativePath(expectedValue: String): HavePropertyMatcher[TreeParserEventCandidate, Path] =
relativePath(Paths.get(expectedValue))
def parser(expectedValue: String): HavePropertyMatcher[TreeParserEventCandidate, String] =
MatcherHelpers.propertyMatcher(
propertyName = "candidate parser name",
expected = expectedValue,
test = (x: TreeParserEventCandidate) => x.parser
)
def errorMessage(first: String, other: String*): HavePropertyMatcher[TreeParserEventScanError, String] =
MatcherHelpers.subStringPropertyMatcher(
propertyName = "error message content",
expected = first +: other,
test = (x: TreeParserEventScanError) => x.error.getMessage,
display = (x: TreeParserEventScanError) => x.error.toString
)
def errorRelativePath(expectedValue: Path): HavePropertyMatcher[TreeParserEventScanError, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: TreeParserEventScanError) => x.relativePath
)
def errorRelativePath(expectedValue: String): HavePropertyMatcher[TreeParserEventScanError, Path] =
errorRelativePath(Paths.get(expectedValue))
def numCandidates(expectedValue: Long): HavePropertyMatcher[TreeParserEventEnd, Long] =
MatcherHelpers.propertyMatcher(
propertyName = "number of candidate calculations",
expected = expectedValue,
test = (x: TreeParserEventEnd) => x.numCandidates
)
}
object CalculationParserEventMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[CalculationParserEvent, Path] =
......
package eu.nomad_lab.integrated_pipeline_tests.matchers
import java.nio.file.{ Path, Paths }
import eu.nomad_lab.integrated_pipeline.messages.{ TreeParserEvent, TreeParserEventCandidate, TreeParserEventEnd, TreeParserEventScanError }
import org.scalatest.matchers.HavePropertyMatcher
trait MatcherTreeParserEvent {
def basePath(expectedValue: Path): HavePropertyMatcher[TreeParserEvent, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "tree base path",
expected = expectedValue,
test = (x: TreeParserEvent) => x.treeTask.treeBasePath
)
def basePath(expectedValue: String): HavePropertyMatcher[TreeParserEvent, Path] =
basePath(Paths.get(expectedValue))
}
object MatcherTreeParserEventStart extends MatcherTreeParserEvent
object MatcherTreeParserEventCandidate extends MatcherTreeParserEvent {
def relativePath(expectedValue: Path): HavePropertyMatcher[TreeParserEventCandidate, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: TreeParserEventCandidate) => x.relativePath
)
def relativePath(expectedValue: String): HavePropertyMatcher[TreeParserEventCandidate, Path] =
relativePath(Paths.get(expectedValue))
def parser(expectedValue: String): HavePropertyMatcher[TreeParserEventCandidate, String] =
MatcherHelpers.propertyMatcher(
propertyName = "candidate parser name",
expected = expectedValue,
test = (x: TreeParserEventCandidate) => x.parser
)
}
object MatcherTreeParserEventScanError extends MatcherTreeParserEvent {
def errorMessage(first: String, other: String*): HavePropertyMatcher[TreeParserEventScanError, String] =
MatcherHelpers.subStringPropertyMatcher(
propertyName = "error message content",
expected = first +: other,
test = (x: TreeParserEventScanError) => x.error.getMessage,
display = (x: TreeParserEventScanError) => x.error.toString
)
def relativePath(expectedValue: Path): HavePropertyMatcher[TreeParserEventScanError, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: TreeParserEventScanError) => x.relativePath
)
def relativePath(expectedValue: String): HavePropertyMatcher[TreeParserEventScanError, Path] =
relativePath(Paths.get(expectedValue))
}
object MatcherTreeParserEventEnd extends MatcherTreeParserEvent {
def numCandidates(expectedValue: Long): HavePropertyMatcher[TreeParserEventEnd, Long] =
MatcherHelpers.propertyMatcher(
propertyName = "number of candidate calculations",
expected = expectedValue,
test = (x: TreeParserEventEnd) => x.numCandidates
)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment