class CookbookLoader {

  public Cookbook load(InputStream ingredients) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    Cookbook cookbook = null;
    try {
      cookbook = mapper.readValue(ingredients, Cookbook.class);
    } catch (IOException e) {
      throw new RuntimeException("could not load recipe cookbook from input stream", e);
    }
    validate(cookbook);
    return cookbook;
  }

}

class CookbookLoaderTest {

  private CookbookLoader loader;

  @Test(expected = RuntimeException.class)
  public void testLoad_throwsOnOptionalWithoutName() {

    String ingredients =
        String.join(
            "\n",
            "domain: 'test'",
            "ingredients:",
            "  - name: 'fooIngredient'",
            "    optionals:",
            "      - type: 'string'");

    loader.load(toStream(ingredients));
  }

}