### Question:
BatteryInfoParser { public static ArrayList<Info> parse(CharSequence str) { Matcher parse = EXTRACT_KEY_VALUE.matcher(str); ArrayList<Info> infos = new ArrayList<>(); while (parse.find()){ infos.add(new Info(parse.group(1).trim(),parse.group(2).trim())); } return infos; }  static ArrayList<Info> parse(CharSequence str);  }### Answer:
@Test public void equalSeparteTheKeyFromTheValue(){ String testStr = KEY1+'='+VALUE1; ArrayList<Info> res = BatteryInfoParser.parse(testStr); assertEquals(1,res.size()); Info info = res.get(0); assertEquals(KEY1,info.title); assertEquals(VALUE1,info.value); }
@Test public void theSpaceBeforeTheEqualAreIngored(){ String testStr = " "+KEY1+" = "+VALUE1+" "; ArrayList<Info> res = BatteryInfoParser.parse(testStr); assertEquals(1,res.size()); Info info = res.get(0); assertEquals(KEY1,info.title); assertEquals(VALUE1,info.value); }
@Test public void multipleItemsAreSeparatedByNewLine(){ String testStr = " "+KEY1+" = "+VALUE1+" \n"+ KEY2+"="+VALUE2; ArrayList<Info> res = BatteryInfoParser.parse(testStr); assertEquals(2,res.size()); Info info = res.get(0); assertEquals(KEY1,info.title); assertEquals(VALUE1,info.value); info = res.get(1); assertEquals(KEY2,info.title); assertEquals(VALUE2,info.value); }
@Test public void anInvalidStringWillReturnAnEmptyList(){ ArrayList<Info> res = BatteryInfoParser.parse(VALUE1); assertTrue(res.isEmpty()); }