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/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..04fa7ce 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..de20e14 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