Example #1
0
  @Test
  public void parseShouldThrowExceptionWhenEntryIsInvalid() throws Exception {
    thrown.expect(ConfigException.class);

    ConfigList list = new ConfigList(configEntry);

    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();

    Map<String, Object> d1 = new HashMap<String, Object>();
    d1.put("k1", "v2");

    Map<String, Object> d2 = new HashMap<String, Object>();
    d2.put("k2", "v3");

    data.add(d1);
    data.add(d2);

    when(configEntry.parse(anyString(), any())).thenThrow(new ConfigException("error"));

    list.parse("name", data);
  }
Example #2
0
  @Test
  public void parseShouldParseAllConfigEntriesAndReturnList() throws Exception {
    ConfigList list = new ConfigList(configEntry);

    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();

    Map<String, Object> d1 = new HashMap<String, Object>();
    d1.put("k1", "v2");

    Map<String, Object> d2 = new HashMap<String, Object>();
    d2.put("k1", "v3");

    data.add(d1);
    data.add(d2);

    when(configEntry.parse("name[0]", d1)).thenReturn(d1);
    when(configEntry.parse("name[1]", d2)).thenReturn(d2);

    List result = list.parse("name", data);

    Assert.assertEquals(2, result.size());
    Assert.assertEquals(d1, data.get(0));
    Assert.assertEquals(d2, data.get(1));
  }