Skip to content

Commit

Permalink
Fixed pull up and push down lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
anchouls committed Jan 25, 2024
1 parent 9eca5eb commit 31a399b
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 177 deletions.
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.");
}
}

0 comments on commit 31a399b

Please sign in to comment.