Skip to content

Commit

Permalink
#15 First implementation of action that creates PDD todo
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Vinogradov committed Aug 7, 2019
1 parent b598688 commit 6ff74f8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pdd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--source=.
--verbose
--exclude .gradle/**/*
--exclude .build/**/*
--exclude build/**/*
--exclude .idea/**/*
--exclude gradlew
--exclude gradlew.bat
Expand Down
14 changes: 5 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ plugins {
jacoco
}

val junit5Version = "5.3.1"
val kotlinVersion = plugins.getPlugin(KotlinPluginWrapper::class.java).kotlinPluginVersion

dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
}

repositories {
jcenter()
}

// @todo #15:30 Set limit of code coverage. To ensure that the project has a good quality let's use high coverage demand.
tasks.jacocoTestReport {
reports {
xml.isEnabled = true
Expand All @@ -41,8 +34,11 @@ tasks.jacocoTestReport {
executionData(File("build/jacoco/test.exec"))
}

dependencies{
testImplementation("io.mockk:mockk:1.9.3")
}

tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aivinog1.pdd.plugin.template

import com.intellij.lang.LanguageCommenters
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.diagnostic.Logger
import com.intellij.psi.PsiFile

class CreateNewPddAction(private val logger: Logger = Logger.getInstance("CreateNewPddAction")) : AnAction("Create a new PDD.") {

override fun actionPerformed(e: AnActionEvent) {
val file = e.getData(CommonDataKeys.PSI_FILE)
if (file != null) {
actionPerformed(file)
}
}


// @todo #15:30m For now, this method did nothing but only logging the language and the comment symbol.
// Needs to implement inserting a todo.
private fun actionPerformed(file: PsiFile) {
val language = file.language
val commenter = LanguageCommenters.INSTANCE.forLanguage(language)
val lineCommentPrefix = commenter.lineCommentPrefix
logger.trace("Current language: $language. It's comment is $lineCommentPrefix.")
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
description="Test Action">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>
<!-- @todo #15:30m Let's register CreateNewPddAction. Now this task is not registered and didn't appear on the menu. Let's implement this.-->
</actions>
</idea-plugin>
4 changes: 2 additions & 2 deletions src/test/kotlin/com/aivinog1/pdd/plugin/TestTaskTest.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.aivinog1.pdd.plugin

import org.junit.jupiter.api.Test
import org.junit.Test
import kotlin.test.assertNotNull

/**
* @todo #20:30m This is a dummy test that verify that report working. Needs to remove this or add some cases.
*/
class TestTaskTest {

val testTask: TestTask = TestTask()
private val testTask: TestTask = TestTask()

@Test
fun test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.aivinog1.pdd.plugin.template

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.diagnostic.Logger
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixture4TestCase
import io.mockk.*
import org.junit.Test

class CreateNewPddActionTest: LightPlatformCodeInsightFixture4TestCase() {

private val logger: Logger = mockk()
private val createNewPddAction = CreateNewPddAction(logger = logger)

override fun getTestDataPath(): String {
return "testData"
}

@Test
fun `test that simple java file has comment`() {
every { logger.trace("Current language: Language: JAVA. It's comment is //.") } just Runs
// @todo #15:30m After CreateNewPddAction became registered let's drop this mock and invite action via the IntelliJ platform.
val actionEvent: AnActionEvent = mockk()
every { actionEvent.getData(CommonDataKeys.PSI_FILE) } returns myFixture.configureByFile("SimpleJavaClass.java")
createNewPddAction.actionPerformed(actionEvent)
verify {
logger.trace("Current language: Language: JAVA. It's comment is //.")
}
confirmVerified(logger)
}
}
5 changes: 5 additions & 0 deletions testData/SimpleJavaClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.test;

class Test {
private String test;
}

4 comments on commit 6ff74f8

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6ff74f8 Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 15-4f88ae36 discovered in build.gradle.kts and submitted as #37. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6ff74f8 Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 15-e5aa706c discovered in src/main/kotlin/com/aivinog1/pdd/plugin/template/CreateNewPddAction.kt and submitted as #38. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6ff74f8 Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 15-e3928364 discovered in src/main/resources/META-INF/plugin.xml and submitted as #39. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6ff74f8 Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 15-d8babfd8 discovered in src/test/kotlin/com/aivinog1/pdd/plugin/template/CreateNewPddActionTest.kt and submitted as #40. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.