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

Feedback #1

Open
wants to merge 2 commits into
base: feedback
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>2.0.21</kotlin.version>
</properties>

<dependencies>
Expand All @@ -34,6 +35,17 @@
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -86,5 +98,59 @@
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>${maven.compiler.target}</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions src/main/java/com/serenitydojo/Hamster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.serenitydojo;

public class Hamster extends Pet {
private String favoriteWheel;

public Hamster(String name, int age, String favoriteWheel) {
super(name, age);
this.favoriteWheel = favoriteWheel;
}

public String getFavoriteWheel() {
return favoriteWheel;
}

public void setFavoriteWheel(String favoriteWheel) {
this.favoriteWheel = favoriteWheel;
}

@Override
public String play() {
return "runs in " + favoriteWheel;
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/serenitydojo/Pet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.serenitydojo;

public class Pet {
private String name;
private int age;

public Pet(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String play() {
return "plays";
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/serenitydojo/model/Feeder.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.serenitydojo.model;

public class Feeder {
public String feeds(String animal, boolean isPremium) {
public FoodType feeds(String animal, boolean isPremium) {
if (animal.equals("Cat")) {
return (isPremium) ? "Salmon" : "Tuna";
return (isPremium) ? FoodType.SALMON: FoodType.TUNA;
} else if (animal.equals("Dog")) {
return "Dog Food";
return FoodType.DOG_FOOD;
}

return "Cabbage";
return FoodType.CABBAGE;

}
}
5 changes: 5 additions & 0 deletions src/main/java/com/serenitydojo/model/FoodType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.serenitydojo.model;

public enum FoodType {
TUNA, CABBAGE, LETTUCE, SALMON, DOG_FOOD, DELUXE_DOG_FOOD, UNKNOWN
}
17 changes: 9 additions & 8 deletions src/test/java/com/serenitydojo/WhenFeedingTheAnimals.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.serenitydojo;

import com.serenitydojo.model.Feeder;
import com.serenitydojo.model.FoodType;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -10,36 +11,36 @@ public class WhenFeedingTheAnimals {
public void shouldFeedCatsTuna() {
Feeder feeder = new Feeder();

String food = feeder.feeds("Cat", false);
FoodType food = feeder.feeds("Cat", false);

Assert.assertEquals("Tuna", food);
Assert.assertEquals(FoodType.TUNA, food);
}

@Test
public void shouldFeedHamstersCabbage() {
Feeder feeder = new Feeder();

String food = feeder.feeds("Hamster", false);
FoodType food = feeder.feeds("Hamster", false);

Assert.assertEquals("Cabbage", food);
Assert.assertEquals(FoodType.CABBAGE, food);
}

@Test
public void shouldFeedDogsDogFood() {
Feeder feeder = new Feeder();

String food = feeder.feeds("Dog", false);
FoodType food = feeder.feeds("Dog", false);

Assert.assertEquals("Dog Food", food);
Assert.assertEquals(FoodType.DOG_FOOD, food);
}

@Test
public void shouldFeedPremiumCatsPremiumFood() {
Feeder feeder = new Feeder();

String food = feeder.feeds("Cat", true);
FoodType food = feeder.feeds("Cat", true);

Assert.assertEquals("Salmon", food);
Assert.assertEquals(FoodType.SALMON, food);

}
}