Skip to content

Commit

Permalink
Updated tests in Moving section
Browse files Browse the repository at this point in the history
  • Loading branch information
anchouls committed Jul 31, 2023
1 parent fa3abee commit 894b7ad
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 47 deletions.
82 changes: 52 additions & 30 deletions MovingCode/ApplyPullUpAndPushDownRefactorings/task-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,77 @@ files:
- offset: 0
length: 149
placeholder_text: |-
package jetbrains.refactoring.course.moving
interface Animal {
fun eat()
fun sleep()
fun bark()
fun meow()
}
- name: src/main/kotlin/jetbrains/refactoring/course/moving/Cat.kt
visible: true
placeholders:
- offset: 0
length: 420
placeholder_text: |-
package jetbrains.refactoring.course.moving
class Cat(private val name: String, private val age: Int) : Animal {
override fun eat() {
println("$name the cat is eating.")
}
override fun sleep() {
println("$name the cat is sleeping.")
}
override fun bark() {
println("$name the animal is barking.")
}
override fun meow() {
println("$name the animal is meowing.")
}
fun play() {
println("$name the cat is playing.")
}
override fun eat() {
println("$name the cat is eating.")
}
override fun sleep() {
println("$name the cat is sleeping.")
}
override fun bark() {
println("$name the animal is barking.")
}
override fun meow() {
println("$name the animal is meowing.")
}
fun play() {
println("$name the cat is playing.")
}
}
- name: src/main/kotlin/jetbrains/refactoring/course/moving/Dog.kt
visible: true
placeholders:
- offset: 0
length: 417
placeholder_text: |-
package jetbrains.refactoring.course.moving
class Dog(private val name: String, private val age: Int) : Animal {
override fun eat() {
println("$name the dog is eating.")
}
override fun sleep() {
println("$name the dog is sleeping.")
}
override fun bark() {
println("$name the dog is barking.")
}
override fun meow() {
println("$name the animal is meowing.")
}
fun play() {
println("$name the dog is playing.")
}
override fun eat() {
println("$name the dog is eating.")
}
override fun sleep() {
println("$name the dog is sleeping.")
}
override fun bark() {
println("$name the dog is barking.")
}
override fun meow() {
println("$name the animal is meowing.")
}
fun play() {
println("$name the dog is playing.")
}
}
47 changes: 46 additions & 1 deletion MovingCode/ApplyPullUpAndPushDownRefactorings/test/Tests.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
import org.jetbrains.academy.test.system.test.BaseIjTestClass
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.io.File

class PullUpAndPushDownTest : BaseIjTestClass() {

companion object {

private lateinit var animalText: String

@JvmStatic
@BeforeAll
fun initialize() {
val taskDirectoryPath = System.getProperty("user.dir")
animalText =
File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/Animal.kt").readText()
}
}

@Test
fun testPullUpPlayMethodAndVariables() {
setUp()
myFixture.configureByText("Animal.kt", animalText)
Assertions.assertTrue(hasMethod("play")) {
"Please, pull up the \"play\" method"
}
Assertions.assertTrue(hasProperty("name")) {
"Please, pull up the \"name\" variable"
}
Assertions.assertTrue(hasProperty("age")) {
"Please, pull up the \"age\" variable"
}
}

@Test
fun testPushDownMethods() {
setUp()
myFixture.configureByText("Animal.kt", animalText)
Assertions.assertFalse(hasMethod("bark")) {
"Please, push down the \"bark\" method"
}
Assertions.assertFalse(hasMethod("meow")) {
"Please, push down the \"meow\" method"
}
}

class PullUpAndPushDownTest {
@Test
fun animalClassTest() {
val clazz = animalClass.checkBaseDefinition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ files:
placeholders:
- offset: 0
length: 465
placeholder_text: ""
placeholder_text: |-
package jetbrains.refactoring.course.moving.car
- name: src/main/kotlin/jetbrains/refactoring/course/moving/driver/Driver.kt
visible: true
placeholders:
- offset: 0
length: 502
placeholder_text: ""
placeholder_text: |-
package jetbrains.refactoring.course.moving.driver
67 changes: 55 additions & 12 deletions MovingCode/FindMoreAppropriateClassesForMethods/test/Tests.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
import org.jetbrains.academy.test.system.test.BaseIjTestClass
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.io.File

class MovingTest {
class MovingTest : BaseIjTestClass() {

companion object {

private lateinit var taskDirectoryPath: String

@JvmStatic
@BeforeAll
fun initialize() {
taskDirectoryPath = System.getProperty("user.dir")
}
}

@Test
fun testCarClassMoved() {
Assertions.assertTrue(
File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/car/Car.kt").exists()
) {
"Please, move the \"Car\" class to a separate file"
}
}

@Test
fun testDriverClassMoved() {
Assertions.assertTrue(
File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/driver/Driver.kt").exists()
) {
"Please, move the \"Driver\" class to a separate file"
}
}

@Test
fun testStartMethodMovedToCarClass() {
val carFile = File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/car/Car.kt")
val sourceText = carFile.readText()
setUp()
myFixture.configureByText("Task.kt", sourceText)
Assertions.assertTrue(hasMethod("start")) {
"Please, move the \"start\" method"
}
}

@Test
fun testStopMethodMovedToCarClass() {
val carFile = File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/car/Car.kt")
val sourceText = carFile.readText()
setUp()
myFixture.configureByText("Task.kt", sourceText)
Assertions.assertTrue(hasMethod("stop")) {
"Please, move the \"stop\" method"
}
}

@Test
fun driverClassTest() {
val clazz = driverClass.checkBaseDefinition()
Expand All @@ -16,15 +70,4 @@ class MovingTest {
carClass.checkFieldsDefinition(clazz)
carClass.checkDeclaredMethods(clazz)
}

@Test
fun newFilesCreatedTest() {
val taskDirectoryPath = System.getProperty("user.dir")
val mainFile = File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/Main.kt")
val driverFile = File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/driver/Driver.kt")
val carFile = File("$taskDirectoryPath/src/main/kotlin/jetbrains/refactoring/course/moving/car/Car.kt")
Assertions.assertTrue(mainFile.exists())
Assertions.assertTrue(driverFile.exists())
Assertions.assertTrue(carFile.exists())
}
}
1 change: 1 addition & 0 deletions MovingCode/MovingCodeIntroduction/task-remote-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id: 661218806
2 changes: 1 addition & 1 deletion MovingCode/lesson-remote-info.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
id: 1888793984
id: 121072982
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ allprojects {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20")
testImplementation("junit:junit:4.13.1")

val testSystemVersion = "2.0.3"
val testSystemVersion = "2.0.5"
implementation("org.jetbrains.academy.test.system:core:$testSystemVersion")
implementation("org.jetbrains.academy.test.system:ij:$testSystemVersion")

Expand Down

0 comments on commit 894b7ad

Please sign in to comment.