fix RcProducerTest in All Tests

This commit is contained in:
Vladimir Krivosheev
2016-12-28 13:51:13 +01:00
parent c8e3cf636c
commit 4d4cf5459a
4 changed files with 74 additions and 5 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
import java.util.List;
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
public final class Assertions extends org.assertj.core.api.Assertions {
@@ -37,4 +38,9 @@ public final class Assertions extends org.assertj.core.api.Assertions {
public static StringAssertEx assertThat(@Nullable String actual) {
return new StringAssertEx(actual);
}
@NotNull
public static <ELEMENT> ListAssertEx<ELEMENT> assertThat(@Nullable List<? extends ELEMENT> actual) {
return new ListAssertEx<>(actual);
}
}
@@ -15,7 +15,6 @@
*/
package com.intellij.testFramework.assertions
import com.intellij.rt.execution.junit.FileComparisonFailure
import com.intellij.util.io.readText
import com.intellij.util.io.size
import org.assertj.core.api.AbstractCharSequenceAssert
@@ -67,9 +66,6 @@ class StringAssertEx(actual: String?) : AbstractCharSequenceAssert<StringAssertE
fun isEqualTo(expected: Path) {
isNotNull
val expectedContent = expected.readText()
if (actual != expectedContent) {
throw FileComparisonFailure(null, expectedContent, actual, expected.toString())
}
compareFileContent(actual, expected)
}
}
@@ -0,0 +1,66 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework.assertions
import com.intellij.openapi.util.text.StringUtilRt
import com.intellij.rt.execution.junit.FileComparisonFailure
import com.intellij.util.io.readText
import org.assertj.core.api.ListAssert
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.nodes.Node
import org.yaml.snakeyaml.nodes.Tag
import org.yaml.snakeyaml.representer.Represent
import org.yaml.snakeyaml.representer.Representer
import java.io.StringWriter
import java.nio.file.Path
import java.util.regex.Pattern
class ListAssertEx<ELEMENT>(actual: List<ELEMENT>) : ListAssert<ELEMENT>(actual) {
fun toMatchSnapshot(snapshotFile: Path) {
isNotNull
compareFileContent(actual, snapshotFile)
}
}
private fun dumpData(data: Any): String {
val dumperOptions = DumperOptions()
dumperOptions.isAllowReadOnlyProperties = true
dumperOptions.lineBreak = DumperOptions.LineBreak.UNIX
val yaml = Yaml(DumpRepresenter(), dumperOptions)
val writer = StringWriter()
yaml.dump(data, writer)
return writer.toString()
}
private class DumpRepresenter : Representer() {
init {
representers.put(Pattern::class.java, RepresentDump())
}
private inner class RepresentDump : Represent {
override fun representData(data: Any): Node = representScalar(Tag.STR, data.toString())
}
}
internal fun compareFileContent(actual: Any, snapshotFile: Path) {
val expectedContent = StringUtilRt.convertLineSeparators(snapshotFile.readText())
val actualContent = dumpData(actual)
if (actualContent != expectedContent) {
throw FileComparisonFailure(null, expectedContent, actualContent, snapshotFile.toString())
}
}
@@ -13,5 +13,6 @@
<orderEntry type="library" exported="" scope="TEST" name="JDOM" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="assertJ" level="project" />
<orderEntry type="library" scope="TEST" name="memoryfilesystem" level="project" />
<orderEntry type="library" scope="TEST" name="snakeyaml" level="project" />
</component>
</module>