YamlFixtureParser implements FixtureParser { @SuppressWarnings("unchecked") @Override public Map<String, FixtureMap> parse(String fixture) { Map<String, ? extends Object> fixtures = buildYaml().loadAs(fixture, Map.class);; Map<String, FixtureMap> fixtureMaps = new HashMap<>(); for (String key : fixtures.keySet()) { if (fixtures.get(key) instanceof Map) { FixtureMap fixtureMap = FixtureTemplateWrapper.wrap((Map) fixtures.get(key), key, null); fixtureMap.setRoot(true); fixtureMaps.put(key, fixtureMap); } else { throw new FixtureFormatException(key, " the root of fixture data should be key - value"); } } return fixtureMaps; }  @SuppressWarnings("unchecked") @Override Map<String, FixtureMap> parse(String fixture);  }
@Test public void testParse() throws IOException, URISyntaxException { URI uri = ClassUtils.getDefaultClassLoader().getResource("fixtures/this.yml").toURI(); String fixtureStr = new String(Files.readAllBytes(Paths.get(uri))); Map<String, FixtureMap> fixtureMaps = parser.parse(fixtureStr); FixtureMap beanmother = fixtureMaps.get("beanmother"); assertTrue(beanmother.isRoot()); assertEquals(beanmother.getFixtureName(), "beanmother"); assertTrue(beanmother.get("id") instanceof FixtureValue); assertEquals(beanmother.get("id"), new FixtureValue(1)); assertEquals(beanmother.get("title"), new FixtureValue("beanmother")); assertEquals(beanmother.get("url"), new FixtureValue("https: assertTrue(beanmother.get("authors") instanceof FixtureList); }
@Test(expected = FixtureFormatException.class) public void testFailParseWhenFixtureIsList() { String fixtureStr = "person:\n - JH Shin\n - John"; parser.parse(fixtureStr); }
@Test(expected = FixtureFormatException.class) public void testFailParseWhenFixtureIsStringValue() { String fixtureStr = "person: test1\nanimal: test2"; parser.parse(fixtureStr); }