diff --git a/integrated-pipeline/src/test/scala/eu/nomad_lab/integrated_pipeline_tests/MessageMatchers.scala b/integrated-pipeline/src/test/scala/eu/nomad_lab/integrated_pipeline_tests/MessageMatchers.scala index eb939e59dd89c3b68e36f460d6861bfcb9fd9220..b485fee14518c80b64dd9a044c9384189109786e 100644 --- a/integrated-pipeline/src/test/scala/eu/nomad_lab/integrated_pipeline_tests/MessageMatchers.scala +++ b/integrated-pipeline/src/test/scala/eu/nomad_lab/integrated_pipeline_tests/MessageMatchers.scala @@ -12,109 +12,89 @@ trait MessageMatchers object MessageMatchers extends MessageMatchers -trait FileTreeTaskMatchers { - def basePath(expectedValue: Path) = - new HavePropertyMatcher[FileTreeScanTask, Path] { - def apply(test: FileTreeScanTask) = - HavePropertyMatchResult( - test.treeBasePath == expectedValue, - "tree base path", - expectedValue, - test.treeBasePath - ) +private object Helpers { + def propertyMatcher[T, E](propertyName: String, expected: E, test: T => E): HavePropertyMatcher[T, E] = { + new HavePropertyMatcher[T, E] { + def apply(element: T): HavePropertyMatchResult[E] = { + val actual = test(element) + HavePropertyMatchResult(actual == expected, propertyName, expected, actual) + } + override def toString(): String = s"$propertyName '$expected'" } + } +} + +trait FileTreeTaskMatchers { + def basePath(expectedValue: Path): HavePropertyMatcher[FileTreeScanTask, Path] = + Helpers.propertyMatcher( + propertyName = "tree base path", + expected = expectedValue, + test = (x: FileTreeScanTask) => x.treeBasePath + ) } trait FileParsingTaskMatchers { - def treeTask(expectedValue: FileTreeScanTask) = new HavePropertyMatcher[FileParsingTaskSignal, FileTreeScanTask] { - def apply(test: FileParsingTaskSignal) = - HavePropertyMatchResult( - test.treeTask == expectedValue, - "parent tree task", - expectedValue, - test.treeTask - ) - } + def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingTaskSignal, FileTreeScanTask] = + Helpers.propertyMatcher( + propertyName = "parent tree task", + expected = expectedValue, + test = (x: FileParsingTaskSignal) => x.treeTask + ) - def relativePath(expectedValue: Path) = new HavePropertyMatcher[FileParsingTask, Path] { - def apply(test: FileParsingTask) = HavePropertyMatchResult( - test.relativePath == expectedValue, - "relative file path", - expectedValue, - test.relativePath + def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingTask, Path] = + Helpers.propertyMatcher( + propertyName = "relative file path", + expected = expectedValue, + test = (x: FileParsingTask) => x.relativePath ) - } def relativePath(expectedValue: String): HavePropertyMatcher[FileParsingTask, Path] = { relativePath(Paths.get(expectedValue)) } - def extractedPath(expectedValue: Option[Path]) = new HavePropertyMatcher[FileParsingTask, Option[Path]] { - def apply(test: FileParsingTask) = HavePropertyMatchResult( - test.extractedPath == expectedValue, - "temporary extracted file path", - expectedValue, - test.extractedPath + def extractedPath(expectedValue: Option[Path]): HavePropertyMatcher[FileParsingTask, Option[Path]] = + Helpers.propertyMatcher( + propertyName = "temporary extracted file path", + expected = expectedValue, + test = (x: FileParsingTask) => x.extractedPath ) - } def extractedPathString(expectedValue: Option[String]): HavePropertyMatcher[FileParsingTask, Option[Path]] = { extractedPath(expectedValue.map(Paths.get(_))) } - def numParsingTasks(expectedValue: Long) = - new HavePropertyMatcher[FileParsingSignalEndTree, Long] { - def apply(test: FileParsingSignalEndTree) = HavePropertyMatchResult( - test.numParsingTasks == expectedValue, - "number of identified candidate calculations", - expectedValue, - test.numParsingTasks - ) - } + def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileParsingSignalEndTree, Long] = + Helpers.propertyMatcher( + propertyName = "number of identified candidate calculations", + expected = expectedValue, + test = (x: FileParsingSignalEndTree) => x.numParsingTasks + ) + } trait FileParsingResultMatchers { - def treeTask(expectedValue: FileTreeScanTask) = - new HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] { - def apply(test: FileParsingResultSignal) = - HavePropertyMatchResult( - test.treeTask == expectedValue, - "parent tree task", - expectedValue, - test.treeTask - ) - } - def status(expectedValue: ParseResult) = - new HavePropertyMatcher[FileParsingResult, ParseResult] { - def apply(test: FileParsingResult) = - HavePropertyMatchResult( - test.result == expectedValue, - "parsing result status", - expectedValue, - test.result - ) - } + def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] = + Helpers.propertyMatcher( + propertyName = "parent tree task", + expected = expectedValue, + test = (x: FileParsingResultSignal) => x.treeTask + ) - def relativePath(expectedValue: Path) = - new HavePropertyMatcher[FileParsingResult, Path] { - def apply(test: FileParsingResult) = - HavePropertyMatchResult( - test.task.relativePath == expectedValue, - "relative file path", - expectedValue, - test.task.relativePath - ) - } + def status(expectedValue: ParseResult): HavePropertyMatcher[FileParsingResult, ParseResult] = + Helpers.propertyMatcher( + propertyName = "parsing result status", + expected = expectedValue, + test = (x: FileParsingResult) => x.result + ) - def relativePath(expectedValue: String) = - new HavePropertyMatcher[FileParsingResult, Path] { - def apply(test: FileParsingResult) = - HavePropertyMatchResult( - test.task.relativePath == Paths.get(expectedValue), - "relative file path", - Paths.get(expectedValue), - test.task.relativePath - ) - } + def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingResult, Path] = + Helpers.propertyMatcher( + propertyName = "relative file path", + expected = expectedValue, + test = (x: FileParsingResult) => x.task.relativePath + ) + + def relativePath(expectedValue: String): HavePropertyMatcher[FileParsingResult, Path] = + relativePath(Paths.get(expectedValue)) } \ No newline at end of file