MapToEntryConverter { ParameterEntry asEntry(Parameter metadata, MapEntry entryMap) { String[] levelValues = new String[metadata.getLevels().size()]; int index = 0; for (Level level : metadata.getLevels()) { levelValues[index] = asString(level, entryMap.get(level.getName())); index++; } return new SimpleParameterEntry(levelValues); } MapToEntryConverter(ParamEngineRuntimeConfig engineConfig);   }
@Test public void shouldReturnStarStringWhenMapValueStarObject() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("star")); MapEntry map = new MapEntry().put("star", Star.star()); ParameterEntry entry = converter.asEntry(metadata, map); assertThat(entry).hasLevels("*"); }
@Test public void shouldReturnEmptyStringWhenNullLevelValueAndNoTypeRegistered() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("null")); MapEntry map = new MapEntry().put("null", null); ParameterEntry entry = converter.asEntry(metadata, map); assertThat(entry).hasLevels(""); }
@Test public void shouldReturnObjectToStringWhenNoTypeRegistered() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("string")); MapEntry map = new MapEntry().put("string", "something"); ParameterEntry entry = converter.asEntry(metadata, map); assertThat(entry).hasLevels("something"); }
@Test public void shouldReturnStringEncodedByTypeHandlerWhenTypeRegistered() throws ParseException { Date date = SimpleDateFormatPool.get("yyyy-MM-dd").parse("2013-12-04"); Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("date").withType("date")); MapEntry map = new MapEntry().put("date", date); ParameterEntry entry = converter.asEntry(metadata, map); assertThat(entry).hasLevels("2013-12-04"); }
@Test public void shouldWorkForMultipleLevelValues() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("string")) .withLevel(new SimpleLevel().withName("string2")); MapEntry map = new MapEntry().put("string", "something") .put("string2", "else"); ParameterEntry entry = converter.asEntry(metadata, map); assertThat(entry).hasLevels("something", "else"); }