Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ plugins {
group = providers.gradleProperty("pluginGroup").get()
version = providers.gradleProperty("pluginVersion").get()

// Set the JVM language level used to build the project.
kotlin {
jvmToolchain(17)
compilerOptions {
freeCompilerArgs.add("-opt-in=kotlin.contracts.ExperimentalContracts")
}
}

// Configure project's dependencies
repositories {
mavenCentral()

Expand All @@ -36,15 +34,12 @@ repositories {
}
}

// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
testImplementation(libs.junit)
testImplementation(libs.groovy)
testImplementation(libs.mockito)
testImplementation(libs.opentest4j)

// TODO: use Mockito!
testImplementation("org.easymock:easymock:5.6.0")

// IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
intellijPlatform {
create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/akefirad/groom/spock/SpockSpecUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import kotlin.contracts.contract
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement
import kotlin.contracts.contract

object SpockSpecUtils {
private const val SPOCK_SPEC_CLASS: String = "spock.lang.Specification"

@JvmStatic
fun PsiFile.hasAnySpecification(): Boolean {
return this is GroovyFile && children
.filterIsInstance<PsiClass>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExp
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement
import org.junit.Test

import static com.akefirad.oss.easymock.EasyMock.mock
import static com.intellij.openapi.util.TextRange.EMPTY_RANGE
import static org.easymock.EasyMock.expect
import static org.easymock.EasyMock.replay
import static org.easymock.EasyMock.verify
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.times
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when

class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase {

Expand All @@ -32,9 +32,7 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
// given:
def subject = new GroovyFoldingBuilder()
def root = mock(PsiJavaFile)

expect(root.node).andReturn(null)
replay(root)
when(root.node).thenReturn(null)

// when:
def result = subject.buildFoldRegions(root, mock(Document), false)
Expand All @@ -43,7 +41,7 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
assert result.length == 0

// and:
verify(root)
verify(root).node
}

@Test
Expand All @@ -55,10 +53,9 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
def root = mock(PsiElement)
def constructor = mock(GrNewExpression)

expect(root.getChildren()).andReturn([constructor] as PsiElement[])
expect(constructor.getText()).andReturn("new Foo(\n param") // Not properly closed - missing )
expect(constructor.getChildren()).andReturn([] as PsiElement[])
replay(root, constructor)
when(root.children).thenReturn([constructor] as PsiElement[])
when(constructor.text).thenReturn("new Foo(\n param") // Not properly closed - missing )
when(constructor.children).thenReturn([] as PsiElement[])

// when:
subject.addConstructorCallFoldRegions(descriptors, root)
Expand All @@ -67,7 +64,9 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
assert descriptors.isEmpty()

// and:
verify(root, constructor)
verify(root).children
verify(constructor).text
verify(constructor).children
}

@Test
Expand All @@ -79,11 +78,10 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
def root = mock(PsiElement)
def constructor = mock(GrNewExpression)

expect(root.getChildren()).andReturn([constructor] as PsiElement[])
expect(constructor.getText()).andReturn("new Foo(\n bar\n)").anyTimes()
expect(constructor.getArgumentList()).andReturn(null) // For the args check
expect(constructor.getChildren()).andReturn([] as PsiElement[])
replay(root, constructor)
when(root.children).thenReturn([constructor] as PsiElement[])
when(constructor.text).thenReturn("new Foo(\n)")
when(constructor.argumentList).thenReturn(null) // For the args check
when(constructor.children).thenReturn([] as PsiElement[])

// when:
subject.addConstructorCallFoldRegions(descriptors, root)
Expand All @@ -92,23 +90,24 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
assert descriptors.isEmpty()

// and:
verify(root, constructor)
verify(root).children
verify(constructor, times(2)).text
verify(constructor).argumentList
verify(constructor).children
}

@Test
void 'getLanguagePlaceholderText should fail when node is not supported type'() {
// given:
def subject = new GroovyFoldingBuilder()
def node = mock(ASTNode)

expect(node.getPsi()).andReturn(mock(PsiElement))
replay(node)
when(node.psi).thenReturn(mock(PsiElement))

// expect:
assertThrows(IllegalArgumentException) { subject.getLanguagePlaceholderText(node, EMPTY_RANGE) }

// and:
verify(node)
verify(node).psi
}

@Test
Expand All @@ -118,9 +117,8 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
def node = mock(ASTNode)
def constructor = mock(GrNewExpression)

expect(node.getPsi()).andReturn(constructor)
expect(constructor.getReferenceElement()).andReturn(null)
replay(node, constructor)
when(node.psi).thenReturn(constructor)
when(constructor.referenceElement).thenReturn(null)

// when:
def result = subject.getLanguagePlaceholderText(node, EMPTY_RANGE)
Expand All @@ -129,7 +127,8 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
assert result == "new (...)"

// and:
verify(node, constructor)
verify(node).psi
verify(constructor).referenceElement
}

@Test
Expand All @@ -140,10 +139,9 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
def constructor = mock(GrNewExpression)
def reference = mock(GrCodeReferenceElement)

expect(node.getPsi()).andReturn(constructor)
expect(constructor.getReferenceElement()).andReturn(reference)
expect(reference.getReferenceName()).andReturn(null)
replay(node, constructor, reference)
when(node.psi).thenReturn(constructor)
when(constructor.referenceElement).thenReturn(reference)
when(reference.referenceName).thenReturn(null)

// when:
def result = subject.getLanguagePlaceholderText(node, EMPTY_RANGE)
Expand All @@ -152,7 +150,9 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
assert result == "new (...)"

// and:
verify(node, constructor, reference)
verify(node).psi
verify(constructor).referenceElement
verify(reference).referenceName
}

@Test
Expand All @@ -163,9 +163,8 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
def constructor = mock(GrNewExpression)
def argumentList = mock(PsiElement)

expect(node.getPsi()).andReturn(argumentList)
expect(argumentList.getParent()).andReturn(constructor)
replay(node, argumentList, constructor)
when(node.psi).thenReturn(argumentList)
when(argumentList.parent).thenReturn(constructor)

// when:
def result = subject.getLanguagePlaceholderText(node, EMPTY_RANGE)
Expand All @@ -174,7 +173,8 @@ class GroovyFoldingBuilderTest extends LightPlatformCodeInsightFixture4TestCase
assert result == "(...)"

// and:
verify(node, argumentList, constructor)
verify(node).psi
verify(argumentList).parent
}

}
7 changes: 0 additions & 7 deletions src/test/groovy/com/akefirad/oss/easymock/EasyMock.groovy

This file was deleted.

Loading