### Question:
GroupKey { static public String[] parseKey(String groupKey) { StringBuilder sb = new StringBuilder(); String dataId = null; String group = null; String tenant = null; for (int i = 0; i < groupKey.length(); ++i) { char c = groupKey.charAt(i); if ('+' == c) { if (null == dataId) { dataId = sb.toString(); sb.setLength(0); } else if (null == group) { group = sb.toString(); sb.setLength(0); } else { throw new IllegalArgumentException("invalid groupkey:" + groupKey); } } else if ('%' == c) { char next = groupKey.charAt(++i); char nextnext = groupKey.charAt(++i); if ('2' == next && 'B' == nextnext) { sb.append('+'); } else if ('2' == next && '5' == nextnext) { sb.append('%'); } else { throw new IllegalArgumentException("invalid groupkey:" + groupKey); } } else { sb.append(c); } } if (StringUtils.isBlank(group)) { group = sb.toString(); if (group.length() == 0) { throw new IllegalArgumentException("invalid groupkey:" + groupKey); } } else { tenant = sb.toString(); if (group.length() == 0) { throw new IllegalArgumentException("invalid groupkey:" + groupKey); } } return new String[] {dataId, group, tenant}; }  static String getKey(String dataId, String group); static String getKeyTenant(String dataId, String group, String tenant); static String getKey(String dataId, String group, String datumStr); static String[] parseKey(String groupKey);  }### Answer:
@Test public void test_parseGroupKey_非法的() { String key = "11111+222+333333+444"; try { GroupKey2.parseKey(key); Assert.fail(); } catch (IllegalArgumentException e) { System.out.println(e.toString()); } key = "11111+"; try { GroupKey2.parseKey(key); Assert.fail(); } catch (IllegalArgumentException e) { System.out.println(e.toString()); } key = "11111%29+222"; try { GroupKey2.parseKey(key); Assert.fail(); } catch (IllegalArgumentException e) { System.out.println(e.toString()); } key = "11111%2b+222"; try { GroupKey2.parseKey(key); Assert.fail(); } catch (IllegalArgumentException e) { System.out.println(e.toString()); } key = "11111%25+222"; String[] pair = GroupKey2.parseKey(key); Assert.assertEquals("11111%", pair[0]); Assert.assertEquals("222", pair[1]); }
@Test public void testParseKey() { Assert.assertArrayEquals(new String[]{null, "f+oo", null}, GroupKey.parseKey("f%2Boo")); Assert.assertArrayEquals(new String[]{null, "f%oo", null}, GroupKey.parseKey("f%25oo")); }
@Test public void testParseKeyIllegalArgumentException1() { thrown.expect(IllegalArgumentException.class); GroupKey.parseKey(""); }
@Test public void testParseKeyIllegalArgumentException2() { thrown.expect(IllegalArgumentException.class); GroupKey.parseKey("f%oo"); }
@Test public void testParseKeyIllegalArgumentException3() { thrown.expect(IllegalArgumentException.class); GroupKey.parseKey("f+o+o+bar"); }