EntryToMapConverter { MapEntry asMap(Parameter metadata, ParameterEntry parameterEntry) { MapEntry map = new MapEntry(parameterEntry.getKey()); int index = 0; for (Level level : metadata.getLevels()) { map.put(level.getName(), asObject(level, parameterEntry.getLevels()[index])); index++; } return map; } EntryToMapConverter(ParamEngineRuntimeConfig engineConfig);   }
@Test public void shouldReturnStarObjectWhenLevelValueIsEqualToStar() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("star")); ParameterEntry entry = new SimpleParameterEntry("*"); MapEntry map = converter.asMap(metadata, entry); assertThat(map.get("star")).isInstanceOf(Star.class); }
@Test public void shouldReturnRawStringWhenNoTypeRegisteredForLevel() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("rawValue")); ParameterEntry entry = new SimpleParameterEntry("something"); MapEntry map = converter.asMap(metadata, entry); assertThat(map.get("rawValue")).isEqualTo("something"); }
@Test public void shouldReturnNullWhenNoTypeRegisteredForLevelAndValueIsNull() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("nullValue")); ParameterEntry entry = new SimpleParameterEntry((String) null); MapEntry map = converter.asMap(metadata, entry); assertThat(map.get("nullValue")).isNull(); }
@Test public void shouldReturnValueConvertedByTypeHandlerWhenTypeDefined() { Parameter metadata = new SimpleParameter().withLevel(new SimpleLevel().withName("date").withType("date")); ParameterEntry entry = new SimpleParameterEntry("2012-02-12"); MapEntry map = converter.asMap(metadata, entry); assertThat(map.getAs("date", Date.class)).isEqualTo("2012-02-12"); }