[test framework] merges dispersed Path assertions

This commit is contained in:
Roman Shevchenko
2016-12-05 13:39:46 +01:00
parent b127b0badd
commit 8f5f475c10
16 changed files with 97 additions and 97 deletions
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.javadoc
import com.intellij.openapi.util.JDOMUtil
import com.intellij.psi.PsiJavaFile
import com.intellij.testFramework.Assertions.assertThat
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
@@ -40,7 +40,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.intellij.testFramework.Assertions.assertThat;
import static com.intellij.testFramework.assertions.Assertions.assertThat;
/**
* @author Anna.Kozlova
@@ -26,7 +26,7 @@ import com.intellij.openapi.project.ProjectManager
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
import com.intellij.project.stateStore
import com.intellij.testFramework.*
import com.intellij.testFramework.Assertions.assertThat
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.io.delete
import com.intellij.util.io.readText
import com.intellij.util.io.write
@@ -18,13 +18,12 @@ package com.intellij.configurationStore
import com.intellij.idea.Bombed
import com.intellij.openapi.components.MainConfigurationStateSplitter
import com.intellij.openapi.components.StateStorage
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.testFramework.ProjectRule
import com.intellij.testFramework.RuleChain
import com.intellij.testFramework.TemporaryDirectory
import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.loadElement
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.hasChildren
import org.jdom.Element
import org.junit.ClassRule
import org.junit.Rule
@@ -27,7 +27,7 @@ import com.intellij.openapi.project.impl.ProjectImpl
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.project.stateStore
import com.intellij.testFramework.*
import com.intellij.testFramework.Assertions.assertThat
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.PathUtil
import com.intellij.util.io.readText
import com.intellij.util.io.systemIndependentPath
@@ -3,7 +3,7 @@ package com.intellij.credentialStore
import com.intellij.ide.passwordSafe.PasswordSafe
import com.intellij.ide.passwordSafe.impl.PasswordSafeImpl
import com.intellij.testFramework.ApplicationRule
import com.intellij.testFramework.Assertions.assertThat
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.testFramework.RuleChain
import com.intellij.testFramework.TemporaryDirectory
import org.junit.ClassRule
@@ -20,8 +20,8 @@ import com.intellij.formatting.CompositeTestBlock
import com.intellij.formatting.engine.testModel.getRoot
import com.intellij.formatting.toFormattingBlock
import com.intellij.openapi.util.TextRange
import com.intellij.testFramework.Assertions
import com.intellij.testFramework.Assertions.assertThat
import com.intellij.testFramework.assertions.Assertions
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.containers.TreeTraversal
import org.junit.Test
@@ -60,7 +60,7 @@ class TestFormattingModelBuilderTest {
assertLeafRanges(rootBlock, 0..3, 4..7, 8..11)
val children = rootBlock.subBlocks
assertThat(children[0].alignment).isNotNull()
assertThat(children[1].alignment).isNotNull()
assertThat(children[0].alignment).isEqualTo(children[2].alignment)
@@ -17,11 +17,11 @@ package com.intellij.formatting.engine.testModelTests
import com.intellij.formatting.engine.testModel.TestBlock
import com.intellij.formatting.engine.testModel.getRoot
import com.intellij.testFramework.Assertions.assertThat
import com.intellij.testFramework.assertions.Assertions.assertThat
import org.junit.Test
class TestModelParserTest {
@Test
fun `test simple block parsing`() {
val children = getBlocks("[a1]block")
@@ -30,7 +30,7 @@ class TestModelParserTest {
val child = children[0]
assertLeaf(child, "a1", "block")
}
@Test
fun `test block with no attributes`() {
val children = getBlocks("[]block")
@@ -53,7 +53,7 @@ class TestModelParserTest {
fun `test multiple blocks`() {
val children = getRoot("[a1]foo \n\n\n \n\n\n [a2]goo").children
assertThat(children).hasSize(3)
assertLeaf(children[0], "a1", "foo")
assertSpace(children[1], " \n\n\n \n\n\n ")
assertLeaf(children[2], "a2", "goo")
@@ -63,31 +63,31 @@ class TestModelParserTest {
fun `test simple block with space`() {
val children = getBlocks("[a1]foo \n ")
assertThat(children).hasSize(2)
assertLeaf(children[0], "a1", "foo")
assertSpace(children[1], " \n ")
}
@Test
fun `test composite block`() {
var children = getBlocks("[]([]foo \n \n \n [a3]goo)")
assertThat(children).hasSize(1)
children = (children[0] as TestBlock.Composite).children
assertThat(children).hasSize(3)
assertLeaf(children[0], "", "foo")
assertSpace(children[1], " \n \n \n ")
assertLeaf(children[2], "a3", "goo")
}
@Test
fun `test multiple composite blocks`() {
var children = getBlocks("[]([]([]foo \n\n\n []goo) \n\n\n []([]woo))")
assertThat(children).hasSize(1)
children = (children[0] as TestBlock.Composite).children
assertThat(children).hasSize(3)
assertThat((children[0] as TestBlock.Composite).children).hasSize(3)
assertThat((children[2] as TestBlock.Composite).children).hasSize(1)
}
@@ -95,7 +95,7 @@ class TestModelParserTest {
@Test
fun `test nested composite blocks`() {
var children = getBlocks("[a0]([a1]([a2]([a3]([a4]foo))))")
for (i in 0..3) {
assertThat(children).hasSize(1)
val child = children[0] as TestBlock.Composite
@@ -109,13 +109,13 @@ class TestModelParserTest {
}
private fun assertLeaf(testBlock: TestBlock, attrs: String, text: String) {
val leaf = testBlock as TestBlock.Leaf
val leaf = testBlock as TestBlock.Leaf
assertThat(leaf.text).isEqualTo(text)
assertThat(leaf.attributes).isEqualTo(attrs)
}
private fun assertSpace(testBlock: TestBlock, space: String) {
val leaf = testBlock as TestBlock.Space
val leaf = testBlock as TestBlock.Space
assertThat(leaf.text).isEqualTo(space)
}
@@ -23,8 +23,7 @@ import com.intellij.testFramework.InMemoryFsRule
import com.intellij.testFramework.ProjectRule
import com.intellij.util.io.readText
import com.intellij.util.io.write
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.hasChildren
import com.intellij.testFramework.assertions.Assertions.assertThat
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
@@ -32,7 +32,7 @@ import java.util.Collections;
import static com.intellij.openapi.editor.colors.FontPreferencesTest.*;
import static com.intellij.openapi.editor.markup.TextAttributes.USE_INHERITED_MARKER;
import static com.intellij.testFramework.Assertions.assertThat;
import static com.intellij.testFramework.assertions.Assertions.assertThat;
import static java.util.Collections.singletonList;
@SuppressWarnings("Duplicates")
@@ -244,7 +244,7 @@ public class EditorColorsSchemeImplTest extends EditorColorSchemeTestCase {
TextAttributes classFallbackAttrs = scheme.getAttributes(DefaultLanguageHighlighterColors.CLASS_NAME.getFallbackAttributeKey());
assertSame(classFallbackAttrs, classAttrs);
}
public void testPreventCyclicTextAttributeDependency() {
EditorColorsScheme defaultScheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME);
EditorColorsScheme editorColorsScheme = (EditorColorsScheme)defaultScheme.clone();
@@ -271,7 +271,7 @@ public class EditorColorsSchemeImplTest extends EditorColorSchemeTestCase {
TextAttributesKey.removeTextAttributesKey("D");
}
}
public void testIdea152156() throws Exception {
EditorColorsScheme defaultScheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME);
EditorColorsScheme parentScheme = (EditorColorsScheme)defaultScheme.clone();
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework;
package com.intellij.testFramework.assertions;
import org.assertj.core.api.AbstractPathAssert;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -28,9 +27,9 @@ public final class Assertions extends org.assertj.core.api.Assertions {
return new JdomAssert(element);
}
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
@NotNull
public static AbstractPathAssert<?> assertThat(@Nullable Path actual) {
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
public static PathAssertEx assertThat(@Nullable Path actual) {
return new PathAssertEx(actual);
}
}
}
@@ -13,21 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework
package com.intellij.testFramework.assertions
import com.intellij.openapi.util.JDOMUtil
import com.intellij.util.io.readText
import com.intellij.util.io.size
import com.intellij.util.isEmpty
import org.assertj.core.api.AbstractAssert
import org.assertj.core.api.PathAssert
import org.assertj.core.internal.Objects
import org.jdom.Element
import java.io.File
import java.nio.file.Files
import java.nio.file.LinkOption
import java.nio.file.Path
class JdomAssert(actual: Element?) : AbstractAssert<JdomAssert, Element?>(actual, JdomAssert::class.java) {
fun isEmpty(): JdomAssert {
@@ -56,22 +49,11 @@ class JdomAssert(actual: Element?) : AbstractAssert<JdomAssert, Element?>(actual
fun isEqualTo(expected: String): JdomAssert {
isNotNull
Objects.instance().assertEqual(info, JDOMUtil.writeElement(actual!!), expected.trimIndent().removePrefix("""<?xml version="1.0" encoding="UTF-8"?>""").trimStart())
return this
}
}
Objects.instance().assertEqual(
info,
JDOMUtil.writeElement(actual!!),
expected.trimIndent().removePrefix("""<?xml version="1.0" encoding="UTF-8"?>""").trimStart())
class PathAssertEx(actual: Path?) : PathAssert(actual) {
override fun doesNotExist(): PathAssert {
isNotNull
if (Files.exists(actual, LinkOption.NOFOLLOW_LINKS)) {
var error = "Expecting path:\n\t${actual}\nnot to exist"
if (actual.size() < 16 * 1024) {
error += ", content:\n\n${actual.readText()}\n"
}
failWithMessage(error)
}
return this
}
}
@@ -0,0 +1,60 @@
/*
* 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.util.io.readText
import com.intellij.util.io.size
import org.assertj.core.api.PathAssert
import org.assertj.core.internal.ComparatorBasedComparisonStrategy
import org.assertj.core.internal.Iterables
import java.nio.file.Files
import java.nio.file.LinkOption
import java.nio.file.Path
import java.util.*
class PathAssertEx(actual: Path?) : PathAssert(actual) {
override fun doesNotExist(): PathAssert {
isNotNull
if (Files.exists(actual, LinkOption.NOFOLLOW_LINKS)) {
var error = "Expecting path:\n\t${actual}\nnot to exist"
if (actual.size() < 16 * 1024) {
error += ", content:\n\n${actual.readText()}\n"
}
failWithMessage(error)
}
return this
}
fun hasChildren(vararg names: String) {
paths.assertIsDirectory(info, actual)
Iterables(ComparatorBasedComparisonStrategy(
Comparator<Any> { o1, o2 ->
if (o1 is Path && o2 is Path) {
o1.compareTo(o2)
}
else if (o1 is String && o2 is String) {
o1.compareTo(o2)
}
else {
if ((o1 as Path).endsWith(o2 as String)) 0 else -1
}
}
)).assertContainsOnly(info, Files.newDirectoryStream(actual).use { it.toList() }, names)
}
}
+1 -1
View File
@@ -25,7 +25,7 @@
<orderEntry type="module" module-name="images" exported="" scope="RUNTIME" />
<orderEntry type="module" module-name="RegExpSupport" exported="" scope="RUNTIME" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="assertJ" level="project" />
<orderEntry type="library" exported="" name="assertJ" level="project" />
<orderEntry type="library" name="memoryfilesystem" level="project" />
<orderEntry type="module" module-name="boot" />
</component>
@@ -1,39 +0,0 @@
/*
* 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 org.assertj.core.api
import org.assertj.core.internal.ComparatorBasedComparisonStrategy
import org.assertj.core.internal.Iterables
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
fun AbstractPathAssert<*>.hasChildren(vararg names: String) {
paths.assertIsDirectory(info, actual)
Iterables(ComparatorBasedComparisonStrategy(Comparator<kotlin.Any> { o1, o2 ->
if (o1 is Path && o2 is Path) {
o1.compareTo(o2)
}
else if (o1 is String && o2 is String) {
o1.compareTo(o2)
}
else {
if ((o1 as Path).endsWith(o2 as String)) 0 else -1
}
}))
.assertContainsOnly(info, Files.newDirectoryStream(actual).use { it.toList() }, names)
}
@@ -47,7 +47,7 @@ import org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader;
import java.io.File;
import static com.intellij.testFramework.Assertions.assertThat;
import static com.intellij.testFramework.assertions.Assertions.assertThat;
public class EclipseImlTest extends IdeaTestCase {
@NonNls private static final String JUNIT = "JUNIT";