AsciiDocDocumentAttributeScanner { public Map<String, Object> scan(String doc) { if (doc==null) { return Collections.emptyMap(); } if (doc.indexOf(':')==-1) { return Collections.emptyMap(); } Map<String,Object> map = new TreeMap<String, Object>(); String[] lines = doc.split("\n"); for (String line: lines) { if (line==null) { continue; } int index = line.indexOf(':'); if (index!=0) { continue; } int nextIndex = line.indexOf(':',1); if (nextIndex==-1) { continue; } String keyName = line.substring(1,nextIndex).trim(); if (keyName.isEmpty()) { continue; } String value = line.substring(nextIndex+1).trim(); map.put(keyName, value.trim()); } return map; }  Map<String, Object> scan(String doc);  }
@Test public void test_null() { Map<String, Object> result = toTest.scan(null); assertTrue(result.isEmpty()); }
@Test public void test_colon_alone() { Map<String, Object> result = toTest.scan(":"); assertTrue(result.isEmpty()); }
@Test public void test_two_colon_empty() { Map<String, Object> result = toTest.scan("::"); assertTrue(result.isEmpty()); }
@Test public void test_abc_but_empty() { Map<String, Object> result = toTest.scan(":abc:"); assertTrue(result.containsKey("abc")); assertEquals("",result.get("abc")); }
@Test public void test_abc_value() { Map<String, Object> result = toTest.scan(":abc: value"); assertTrue(result.containsKey("abc")); assertEquals("value",result.get("abc")); }
@Test public void test_abc_value1_new_line_def_value2() { Map<String, Object> result = toTest.scan(":abc: value1\n:def:value2"); assertTrue(result.containsKey("abc")); assertEquals("value1",result.get("abc")); assertTrue(result.containsKey("def")); assertEquals("value2",result.get("def")); assertEquals(2,result.size()); }