Package com.manning.siia.kitchen.domain

Examples of com.manning.siia.kitchen.domain.Amount


  @Test
  public void shouldSplitRecipe() {
    Recipe recipe = RecipeObjectMother.friedEggRecipe();
    recipes.send(MessageBuilder.withPayload(recipe).build());
    receiveAndCheckIngredientMessage(new Grocery("egg", new Amount(1, Amount.Unit.PIECES)));
    receiveAndCheckIngredientMessage(new Grocery("butter", new Amount(20, Amount.Unit.GRAMS)));
  }
View Full Code Here


*/
public class RecipeObjectMother {

  public static Recipe friedEggRecipe() {
    Recipe recipe = new Recipe("fried egg");
    recipe.addIngredient(new Ingredient("egg", new Amount(1, Amount.Unit.PIECES), Ingredient.Type.Grocery));
    recipe.addIngredient(new Ingredient("butter", new Amount(20, Amount.Unit.GRAMS), Ingredient.Type.Grocery));
    return recipe;
  }
View Full Code Here

    return recipe;
  }

  public static Recipe steak() {
    Recipe recipe = new Recipe("steak");
    recipe.addIngredient(new Ingredient("steak", new Amount(1, Amount.Unit.PIECES), Ingredient.Type.Meat));
    recipe.addIngredient(new Ingredient("pepper", new Amount(2, Amount.Unit.GRAMS), Ingredient.Type.Grocery));
    recipe.addIngredient(new Ingredient("salt", new Amount(2, Amount.Unit.GRAMS), Ingredient.Type.Grocery));
    return recipe;
  }
View Full Code Here

/**
* @author Iwein Fuld
*/
public class AmountConverter implements Converter {
  public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    Amount amount = (Amount) source;
    StringBuilder builder = new StringBuilder();
    builder.append(amount.getAmount());
    if (amount.getUnit() == Unit.GRAMS) {
      builder.append(" gr");
    }
    writer.setValue(builder.toString());
  }
View Full Code Here

  public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final String value = reader.getValue();
    final String[] strings = value.split(" ");
    if (strings.length == 1) {
      return new Amount(Integer.parseInt(strings[0]), Unit.PIECES);
    } else if (strings[1].trim().equalsIgnoreCase("gr")) {
      return new Amount(Integer.parseInt(strings[0]), Unit.GRAMS);
    } else {
      throw new IllegalArgumentException("Could not parse Amount: " + value);
    }
  }
View Full Code Here

TOP

Related Classes of com.manning.siia.kitchen.domain.Amount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.