Skip to content
Snippets Groups Projects
Commit 07fe7d3a authored by Ernst Larsson-Kapp's avatar Ernst Larsson-Kapp
Browse files

~nya^^

parents
Branches master
No related tags found
No related merge requests found
Showing
with 292 additions and 0 deletions
/target/
*.class
.classpath
.project
.settings
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<groupId>se.liu.ida.tdde45</groupId>
<artifactId>testability-lab</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>testability-lab-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<groupId>se.liu.ida.tdde45</groupId>
<artifactId>testability-lab</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>testability-lab-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
package se.liu.ida.tdde45;
import se.liu.ida.tdde45.food.ingredients.cooked.CookedIngredient;
import se.liu.ida.tdde45.food.ingredients.cooked.CookedIngredientFactory.InvalidIngredientException;
import se.liu.ida.tdde45.food.ingredients.cooked.CookedIngredientFactory.UnknownIngredientException;
import se.liu.ida.tdde45.food.ingredients.raw.RawEgg;
import se.liu.ida.tdde45.food.ingredients.raw.RawPotato;
import se.liu.ida.tdde45.food.ingredients.raw.Yoghurt;
import se.liu.ida.tdde45.food.meals.Breakfast;
import se.liu.ida.tdde45.food.meals.Lunch;
import se.liu.ida.tdde45.house.Bed;
import se.liu.ida.tdde45.house.Bedroom;
import se.liu.ida.tdde45.house.Dresser;
import se.liu.ida.tdde45.house.Fridge;
import se.liu.ida.tdde45.house.Fridge.UnstockedException;
import se.liu.ida.tdde45.house.House;
import se.liu.ida.tdde45.house.Kitchen;
import se.liu.ida.tdde45.house.Stove;
import se.liu.ida.tdde45.house.Stove.FilthyException;
import se.liu.ida.tdde45.house.Stove.UnpoweredException;
import se.liu.ida.tdde45.house.Workbench;
import se.liu.ida.tdde45.singletons.FridgeStocker;
public class Resident {
private House house;
public Resident(House house) {
this.house = house;
}
public Resident(Stove stove, Fridge fridge, Workbench workbench) {
this.house = new House();
house.setKitchen(new Kitchen(stove, fridge, workbench));
}
//private final House house = new House(new Bedroom(new Bed(), new Dresser()));
private boolean sick = false;
protected Breakfast makeBreakfast() throws UnknownIngredientException, UnpoweredException, UnstockedException, FilthyException {
final RawEgg rawEgg = house.getKitchen().getFridge().getEgg();
final Yoghurt yoghurt = house.getKitchen().getFridge().getYoghurt();
final Breakfast breakfast = new Breakfast(house.getKitchen().getStove().boil(rawEgg), yoghurt);
if(house.getKitchen().getStove().isFilthy())
sick = true;
return breakfast;
}
protected Lunch makeLunch() throws InvalidIngredientException, UnknownIngredientException, UnpoweredException, UnstockedException, FilthyException {
final RawEgg rawEgg = house.getKitchen().getFridge().getEgg();
final RawPotato rawPotato = house.getKitchen().getFridge().getPotato();
final CookedIngredient boiledPotato = house.getKitchen().getStove().boil(rawPotato);
final Lunch lunch = new Lunch(house.getKitchen().getWorkbench().process(boiledPotato), house.getKitchen().getStove().boil(rawEgg));
if(house.getKitchen().getStove().isFilthy())
sick = true;
return lunch;
}
public boolean isSick() {
return sick;
}
}
package se.liu.ida.tdde45.food.ingredients;
public interface Ingredient {
}
package se.liu.ida.tdde45.food.ingredients.cooked;
public class BoiledEgg implements CookedIngredient {
}
package se.liu.ida.tdde45.food.ingredients.cooked;
public class BoiledPotato implements CookedIngredient {
}
package se.liu.ida.tdde45.food.ingredients.cooked;
import se.liu.ida.tdde45.food.ingredients.Ingredient;
public interface CookedIngredient extends Ingredient {
}
package se.liu.ida.tdde45.food.ingredients.cooked;
import se.liu.ida.tdde45.food.ingredients.Ingredient;
import se.liu.ida.tdde45.food.ingredients.raw.RawEgg;
import se.liu.ida.tdde45.food.ingredients.raw.RawIngredient;
import se.liu.ida.tdde45.food.ingredients.raw.RawPotato;
@SuppressWarnings("serial")
public class CookedIngredientFactory {
public static CookedIngredient createFromRaw(RawIngredient raw) throws UnknownIngredientException {
if(raw instanceof RawEgg)
return new BoiledEgg();
if(raw instanceof RawPotato)
return new BoiledPotato();
throw new UnknownIngredientException(raw);
}
public static CookedIngredient processIngredient(Ingredient ingredient) throws InvalidIngredientException {
if(ingredient instanceof BoiledPotato)
return new MashedPotato();
throw new InvalidIngredientException(ingredient);
}
public static class UnknownIngredientException extends Exception {
public UnknownIngredientException(RawIngredient raw) {
super("Unknown ingredient: " + raw.getClass());
}
}
public static class InvalidIngredientException extends Exception {
public InvalidIngredientException(Ingredient ingredient) {
super("Ingredient invalid for processing: " + ingredient.getClass());
}
}
}
package se.liu.ida.tdde45.food.ingredients.cooked;
public class MashedPotato implements CookedIngredient {
}
package se.liu.ida.tdde45.food.ingredients.raw;
public class RawEgg implements RawIngredient {
}
package se.liu.ida.tdde45.food.ingredients.raw;
import se.liu.ida.tdde45.food.ingredients.Ingredient;
public interface RawIngredient extends Ingredient {
}
package se.liu.ida.tdde45.food.ingredients.raw;
public class RawPotato implements RawIngredient {
}
package se.liu.ida.tdde45.food.ingredients.raw;
public class Yoghurt implements RawIngredient {
}
package se.liu.ida.tdde45.food.meals;
import java.util.Arrays;
import java.util.List;
import se.liu.ida.tdde45.food.ingredients.Ingredient;
public abstract class AbstractMeal implements Meal {
private final List<Ingredient> ingredients;
public AbstractMeal(Ingredient... ingredients) {
this.ingredients = Arrays.asList(ingredients);
}
public List<Ingredient> getIngredients() {
return ingredients;
}
}
package se.liu.ida.tdde45.food.meals;
import se.liu.ida.tdde45.food.ingredients.Ingredient;
public class Breakfast extends AbstractMeal {
public Breakfast(Ingredient... ingredients) {
super(ingredients);
}
}
package se.liu.ida.tdde45.food.meals;
import se.liu.ida.tdde45.food.ingredients.Ingredient;
public class Lunch extends AbstractMeal {
public Lunch(Ingredient... ingredients) {
super(ingredients);
}
}
package se.liu.ida.tdde45.food.meals;
public interface Meal {
}
package se.liu.ida.tdde45.house;
public class Bed {
}
package se.liu.ida.tdde45.house;
public class Bedroom {
private final Bed bed;
private final Dresser dresser;
public Bedroom(Bed bed, Dresser dresser) {
this.bed = bed;
this.dresser = dresser;
}
public Bed getBed() {
return bed;
}
public Dresser getDresser() {
return dresser;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment