diff --git a/.gitignore b/.gitignore index 7ba49d9..87820d2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ build/ out/ !**/src/main/**/out/ !**/src/test/**/out/ +*-remote-info.yaml +.coursecreator/ \ No newline at end of file diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java index 129e68b..911e261 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java @@ -1,14 +1,32 @@ package jetbrains.refactoring.course.moving; -public interface Animal { +public abstract class Animal { - void eat(); + protected final String name; + protected final int age; - void sleep(); + public Animal(String name, int age) { + this.name = name; + this.age = age; + } - void bark(); + void eat() { + System.out.println(name + " is eating."); + } - void meow(); + void sleep() { + System.out.println(name + " is sleeping."); + } - void play(); + void bark() { + System.out.println(name + " is barking."); + } + + void meow() { + System.out.println(name + " is meowing."); + } + + void play() { + System.out.println(name + " is playing."); + } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java index 8f5f3d4..980e229 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java @@ -1,37 +1,8 @@ package jetbrains.refactoring.course.moving; -public class Cat implements Animal { - - private final String name; - private final int age; +public class Cat extends Animal { public Cat(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public void eat() { - System.out.println(name + " the cat is eating."); - } - - @Override - public void sleep() { - System.out.println(name + " the cat is sleeping."); - } - - @Override - public void bark() { - System.out.println(name + " the animal is barking."); - } - - @Override - public void meow() { - System.out.println(name + " the animal is meowing."); - } - - @Override - public void play() { - System.out.println(name + " the cat is playing."); + super(name, age); } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java index 4544b53..e6aaf2b 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java @@ -1,37 +1,8 @@ package jetbrains.refactoring.course.moving; -public class Dog implements Animal { - - private final String name; - private final int age; +public class Dog extends Animal { public Dog(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public void eat() { - System.out.println(name + " the dog is eating."); - } - - @Override - public void sleep() { - System.out.println(name + " the dog is sleeping."); - } - - @Override - public void bark() { - System.out.println(name + " the dog is barking."); - } - - @Override - public void meow() { - System.out.println(name + " the animal is meowing."); - } - - @Override - public void play() { - System.out.println(name + " the dog is playing."); + super(name, age); } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/test/PullUpTest.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/test/PullUpTest.java index cf67dc8..1497063 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/test/PullUpTest.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPullUpRefactoringPractice/test/PullUpTest.java @@ -11,6 +11,8 @@ public class PullUpTest extends BaseIjTestClass { private static String animalText; + private static String dogText; + private static String catText; @BeforeAll static void beforeAll() throws IOException { @@ -18,6 +20,12 @@ static void beforeAll() throws IOException { Path animalPath = Paths.get(taskDirectoryPath, "src/main/java/jetbrains/refactoring/course/moving/Animal.java"); animalText = Files.readString(animalPath); + Path dogPath = Paths.get(taskDirectoryPath, + "src/main/java/jetbrains/refactoring/course/moving/Dog.java"); + dogText = Files.readString(dogPath); + Path catPath = Paths.get(taskDirectoryPath, + "src/main/java/jetbrains/refactoring/course/moving/Cat.java"); + catText = Files.readString(catPath); } @Test @@ -26,5 +34,11 @@ public void testPullUpPlayMethod() throws Exception { myFixture.configureByText("Animal.java", animalText); Assertions.assertTrue(hasMethod("play"), "Please, pull up the \"play\" method"); + myFixture.configureByText("Dog.java", dogText); + Assertions.assertFalse(hasMethod("play"), + "Please, remove the \"play\" method from the Dog class"); + myFixture.configureByText("Cat.java", catText); + Assertions.assertFalse(hasMethod("play"), + "Please, remove the \"play\" method from the Cat class"); } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java index 310cd5c..00b90cc 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Animal.java @@ -1,10 +1,24 @@ package jetbrains.refactoring.course.moving; -public interface Animal { +public abstract class Animal { - void eat(); + protected final String name; + protected final int age; - void sleep(); + public Animal(String name, int age) { + this.name = name; + this.age = age; + } - void play(); + void eat() { + System.out.println(name + " is eating."); + } + + void sleep() { + System.out.println(name + " is sleeping."); + } + + void play() { + System.out.println(name + " is playing."); + } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java index 4f0365f..74e5814 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Cat.java @@ -1,31 +1,12 @@ package jetbrains.refactoring.course.moving; -public class Cat implements Animal { - - private final String name; - private final int age; +public class Cat extends Animal { public Cat(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public void eat() { - System.out.println(name + " the cat is eating."); - } - - @Override - public void sleep() { - System.out.println(name + " the cat is sleeping."); - } - - public void meow() { - System.out.println(name + " the animal is meowing."); + super(name, age); } - @Override - public void play() { - System.out.println(name + " the cat is playing."); + void meow() { + System.out.println(name + " is meowing."); } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java index b798087..132133f 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/ApplyPushDownRefactoringPractice/src/main/java/jetbrains/refactoring/course/moving/Dog.java @@ -1,31 +1,12 @@ package jetbrains.refactoring.course.moving; -public class Dog implements Animal { - - private final String name; - private final int age; +public class Dog extends Animal { public Dog(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public void eat() { - System.out.println(name + " the dog is eating."); - } - - @Override - public void sleep() { - System.out.println(name + " the dog is sleeping."); - } - - public void bark() { - System.out.println(name + " the dog is barking."); + super(name, age); } - @Override - public void play() { - System.out.println(name + " the dog is playing."); + void bark() { + System.out.println(name + " is barking."); } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Animal.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Animal.java index 6a00037..d9351be 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Animal.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Animal.java @@ -1,12 +1,28 @@ package jetbrains.refactoring.course.moving; -public interface Animal { +public abstract class Animal { - void eat(); + protected final String name; + protected final int age; - void sleep(); + public Animal(String name, int age) { + this.name = name; + this.age = age; + } - void bark(); + void eat() { + System.out.println(name + " is eating."); + } - void meow(); + void sleep() { + System.out.println(name + " is sleeping."); + } + + void bark() { + System.out.println(name + " is barking."); + } + + void meow() { + System.out.println(name + " is meowing."); + } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Cat.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Cat.java index 9177c10..4e24d33 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Cat.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Cat.java @@ -1,36 +1,12 @@ package jetbrains.refactoring.course.moving; -public class Cat implements Animal { - - private final String name; - private final int age; +public class Cat extends Animal { public Cat(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public void eat() { - System.out.println(name + " the cat is eating."); - } - - @Override - public void sleep() { - System.out.println(name + " the cat is sleeping."); - } - - @Override - public void bark() { - System.out.println(name + " the animal is barking."); - } - - @Override - public void meow() { - System.out.println(name + " the animal is meowing."); + super(name, age); } public void play() { - System.out.println(name + " the cat is playing."); + System.out.println(name + " is playing."); } } diff --git a/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Dog.java b/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Dog.java index 85f8512..829c63a 100644 --- a/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Dog.java +++ b/MovingCode/WhatArePullUpAndPushDownRefactorings/WhatArePullUpAndPushDownRefactorings/src/main/java/jetbrains/refactoring/course/moving/Dog.java @@ -1,36 +1,12 @@ package jetbrains.refactoring.course.moving; -public class Dog implements Animal { - - private final String name; - private final int age; +public class Dog extends Animal { public Dog(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public void eat() { - System.out.println(name + " the dog is eating."); - } - - @Override - public void sleep() { - System.out.println(name + " the dog is sleeping."); - } - - @Override - public void bark() { - System.out.println(name + " the dog is barking."); - } - - @Override - public void meow() { - System.out.println(name + " the animal is meowing."); + super(name, age); } public void play() { - System.out.println(name + " the dog is playing."); + System.out.println(name + " is playing."); } } diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Car.java similarity index 91% rename from MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java rename to MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Car.java index e339169..50160a7 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Car.java @@ -1,4 +1,4 @@ -package jetbrains.refactoring.course.moving.car; +package jetbrains.refactoring.course.moving; public class Car { private final int gearsNumber; diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Driver.java similarity index 83% rename from MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java rename to MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Driver.java index b773669..e077311 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Driver.java @@ -1,6 +1,4 @@ -package jetbrains.refactoring.course.moving.driver; - -import jetbrains.refactoring.course.moving.car.Car; +package jetbrains.refactoring.course.moving; public class Driver { private Car car; diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java index a0b8467..ee15593 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java @@ -1,8 +1,5 @@ package jetbrains.refactoring.course.moving; -import jetbrains.refactoring.course.moving.car.Car; -import jetbrains.refactoring.course.moving.driver.Driver; - public class Main { public static void main(String[] args) { Car car = new Car(5); diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task-info.yaml b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task-info.yaml index 878c447..a34d5eb 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task-info.yaml +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task-info.yaml @@ -1,11 +1,11 @@ type: edu custom_name: Find more appropriate classes for methods files: - - name: src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java + - name: src/main/java/jetbrains/refactoring/course/moving/Driver.java visible: true - name: src/main/java/jetbrains/refactoring/course/moving/Main.java visible: true - - name: src/main/java/jetbrains/refactoring/course/moving/car/Car.java - visible: true - name: test/MovingMethodsTest.java visible: false + - name: src/main/java/jetbrains/refactoring/course/moving/Car.java + visible: true diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task.md b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task.md index 09e720c..77bc976 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task.md +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/task.md @@ -2,6 +2,7 @@ Next, you need to move methods to a more appropriate place using the Move refactoring technique. Move some methods from one class to another. +Change the visibility of some methods and variables to the correct one. ### Hints @@ -15,4 +16,12 @@ Use the F6 shortcut to move a code element. Move the `start()` and `stop()` methods to the `Car` class. +Change the visibility of the `start` method to `public`. + +Change the visibility of the `stop` method to `public`. + +Change the visibility of the `setGear` method to `private` - it's only used inside the class. + +Change the visibility of the `engineStarted` variable to `private` - it's only used inside the class. + diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/test/MovingMethodsTest.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/test/MovingMethodsTest.java index 30e8d71..458488e 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/test/MovingMethodsTest.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/test/MovingMethodsTest.java @@ -1,3 +1,4 @@ +import junit.framework.AssertionFailedError; import org.jetbrains.academy.test.system.core.models.Visibility; import org.jetbrains.academy.test.system.core.models.classes.ClassType; import org.jetbrains.academy.test.system.core.models.classes.TestClass; @@ -27,15 +28,15 @@ public class MovingMethodsTest extends BaseIjTestClass { static void beforeAll() throws IOException { String taskDirectoryPath = System.getProperty("user.dir"); Path carPath = Paths.get(taskDirectoryPath, - "src/main/java/jetbrains/refactoring/course/moving/car/Car.java"); + "src/main/java/jetbrains/refactoring/course/moving/Car.java"); carText = Files.readString(carPath); Path driverPath = Paths.get(taskDirectoryPath, - "src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java"); + "src/main/java/jetbrains/refactoring/course/moving/Driver.java"); driverText = Files.readString(driverPath); driverClass = new TestClass( "Driver", - "jetbrains.refactoring.course.moving.driver", + "jetbrains.refactoring.course.moving", Visibility.PUBLIC, ClassType.CLASS, List.of( @@ -78,7 +79,7 @@ static void beforeAll() throws IOException { carClass = new TestClass( "Car", - "jetbrains.refactoring.course.moving.car", + "jetbrains.refactoring.course.moving", Visibility.PUBLIC, ClassType.CLASS, List.of( @@ -169,6 +170,8 @@ public void driverClassTest() { public void carClassTest() { Class clazz = carClass.checkBaseDefinition(); carClass.checkFieldsDefinition(clazz, true); - carClass.checkDeclaredMethods(clazz); + Assertions.assertDoesNotThrow(() -> carClass.checkDeclaredMethods(clazz), + "Please, change the visibility of the start and stop methods to public and the setGear method to private" + ); } } diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Car.java similarity index 88% rename from MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java rename to MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Car.java index 6bc6154..ea33e38 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Car.java @@ -1,4 +1,4 @@ -package jetbrains.refactoring.course.moving.car; +package jetbrains.refactoring.course.moving; public class Car { private final int gearsNumber; diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Driver.java similarity index 86% rename from MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java rename to MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Driver.java index cffa6fd..5e51776 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Driver.java @@ -1,6 +1,4 @@ -package jetbrains.refactoring.course.moving.driver; - -import jetbrains.refactoring.course.moving.car.Car; +package jetbrains.refactoring.course.moving; public class Driver { private Car car; diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java index a0b8467..ee15593 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/Main.java @@ -1,8 +1,5 @@ package jetbrains.refactoring.course.moving; -import jetbrains.refactoring.course.moving.car.Car; -import jetbrains.refactoring.course.moving.driver.Driver; - public class Main { public static void main(String[] args) { Car car = new Car(5); diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task-info.yaml b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task-info.yaml index 54cdfc7..7edeac7 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task-info.yaml +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task-info.yaml @@ -3,9 +3,9 @@ custom_name: Find more appropriate files for classes files: - name: src/main/java/jetbrains/refactoring/course/moving/Main.java visible: true - - name: src/main/java/jetbrains/refactoring/course/moving/car/Car.java - visible: true - - name: src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java - visible: true - name: test/MovingTest.java visible: false + - name: src/main/java/jetbrains/refactoring/course/moving/Car.java + visible: true + - name: src/main/java/jetbrains/refactoring/course/moving/Driver.java + visible: true diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task.md b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task.md index 3d2a2dc..68c341f 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task.md +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/task.md @@ -16,4 +16,8 @@ Move the `Car` class to the `Car.java` file. Move the `Driver` class to the `Driver.java` file. +Change the visibility of the `Driver` class to `public`. + +Change the visibility of the `Car` class to `public`. + diff --git a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/test/MovingTest.java b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/test/MovingTest.java index 34ea23d..6473baf 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/test/MovingTest.java +++ b/MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/test/MovingTest.java @@ -1,3 +1,8 @@ +import org.jetbrains.academy.test.system.core.models.Visibility; +import org.jetbrains.academy.test.system.core.models.classes.ClassType; +import org.jetbrains.academy.test.system.core.models.classes.TestClass; +import org.jetbrains.academy.test.system.core.models.method.TestMethod; +import org.jetbrains.academy.test.system.core.models.variable.TestVariable; import org.jetbrains.academy.test.system.java.test.BaseIjTestClass; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -7,21 +12,129 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; + +import static java.util.Collections.emptyList; public class MovingTest extends BaseIjTestClass { private static String carText; private static String driverText; + private static TestClass driverClass; + private static TestClass carClass; @BeforeAll static void beforeAll() throws IOException { String taskDirectoryPath = System.getProperty("user.dir"); Path carPath = Paths.get(taskDirectoryPath, - "src/main/java/jetbrains/refactoring/course/moving/car/Car.java"); + "src/main/java/jetbrains/refactoring/course/moving/Car.java"); carText = Files.readString(carPath); Path driverPath = Paths.get(taskDirectoryPath, - "src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java"); + "src/main/java/jetbrains/refactoring/course/moving/Driver.java"); driverText = Files.readString(driverPath); + driverClass = new TestClass( + "Driver", + "jetbrains.refactoring.course.moving", + Visibility.PUBLIC, + ClassType.CLASS, + List.of( + new TestVariable( + "car", + "Car", + null, + Visibility.PRIVATE, + false, + true, + false + ) + ), + List.of( + new TestMethod( + "changeCar", + "void", + List.of( + new TestVariable("car", "Car") + ), + Visibility.PUBLIC + ), + new TestMethod( + "driving", + "void", + List.of(new TestVariable("destination", "String")), + Visibility.PRIVATE + ), + new TestMethod( + "driveTo", + "void", + List.of(new TestVariable("destination", "String")), + Visibility.PUBLIC + ), + new TestMethod( + "start", + "void", + emptyList(), + Visibility.PRIVATE + ), + new TestMethod( + "stop", + "void", + emptyList(), + Visibility.PRIVATE + ) + ), + false, + emptyList(), + emptyList() + ); + + carClass = new TestClass( + "Car", + "jetbrains.refactoring.course.moving", + Visibility.PUBLIC, + ClassType.CLASS, + List.of( + new TestVariable( + "gearsNumber", + "int", + null, + Visibility.PRIVATE, + true, + true, + false + ), + new TestVariable( + "engineStarted", + "boolean", + "false", + Visibility.PRIVATE, + false, + false, + false + ), + new TestVariable( + "gear", + "int", + "0", + Visibility.PRIVATE, + false, + false, + false + ) + ), + List.of( + new TestMethod( + "setGear", + "void", + List.of( + new TestVariable("gear", "int") + ), + Visibility.PUBLIC + ) + ), + false, + emptyList(), + emptyList() + ); } @Test @@ -39,4 +152,22 @@ public void testDriverClassMoved() throws Exception { Assertions.assertTrue(hasClass("Driver"), "Please, move the Driver class to a separate file in the driver package"); } + + @Test + public void driverClassTest() { + try { + driverClass.checkBaseDefinition(); + } catch (Exception e) { + Assertions.fail("Please, change the visibility of the Driver class to public"); + } + } + + @Test + public void carClassTest() { + try { + carClass.checkBaseDefinition(); + } catch (Exception e) { + Assertions.fail("Please, change the visibility of the Car class to public"); + } + } } diff --git a/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/car/Car.java b/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/car/Car.java deleted file mode 100644 index 22852ba..0000000 --- a/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/car/Car.java +++ /dev/null @@ -1,3 +0,0 @@ -package jetbrains.refactoring.course.moving.car; - -// TODO diff --git a/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java b/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java deleted file mode 100644 index d02f646..0000000 --- a/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java +++ /dev/null @@ -1,3 +0,0 @@ -package jetbrains.refactoring.course.moving.driver; - -// TODO diff --git a/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/task-info.yaml b/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/task-info.yaml index dc0abd1..8d5fe80 100644 --- a/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/task-info.yaml +++ b/MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/task-info.yaml @@ -3,7 +3,3 @@ custom_name: What is Move refactoring? files: - name: src/main/java/jetbrains/refactoring/course/moving/Main.java visible: true - - name: src/main/java/jetbrains/refactoring/course/moving/car/Car.java - visible: true - - name: src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java - visible: true