Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving code section fix #32

Merged
merged 3 commits into from
Feb 2, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ build/
out/
!**/src/main/**/out/
!**/src/test/**/out/
*-remote-info.yaml
.coursecreator/
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
public class PullUpTest extends BaseIjTestClass {

private static String animalText;
private static String dogText;
private static String catText;

@BeforeAll
static void beforeAll() throws IOException {
String taskDirectoryPath = System.getProperty("user.dir");
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
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jetbrains.refactoring.course.moving.car;
package jetbrains.refactoring.course.moving;

public class Car {
private final int gearsNumber;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Loading
Loading