Labels { public Labels(String... labels) { if (labels.length % 2 != 0) { throw new IllegalArgumentException(); } this.labels = new HashMap<>(labels.length / 2); for (int i = 0; i < labels.length; i += 2) { this.labels.put(labels[i], labels[i + 1]); } checkLabels(this.labels); } Labels(String... labels); private  Labels(Map<String, String> labels); static Labels fromString(String string); Map<String, String> labels(); @Override String toString();  }
@Test public void testLabels() { Labels p = new Labels("foo", "1", "bar", "2"); Map<String, String> m = new HashMap<>(2); m.put("foo", "1"); m.put("bar", "2"); assertThat(p.labels(), is(m)); }