### Question:
LabelUtils { public static List<Label> generatePairs(String tagQuery) { List<Label> pairList = new ArrayList<>(); if (tagQuery != null) { String[] toks = tagQuery.split(","); if (toks != null && toks.length > 0) { for (int i = 0; i < toks.length; i++) { String token = toks[i]; String[] pairToks = token.split("="); if (pairToks != null && pairToks.length == 2) { pairList.add(new Label(pairToks[0], pairToks[1])); } } } } return pairList; }  static List<Label> generatePairs(String tagQuery); static boolean allPairsPresent(List<Label> expectedTags, List<Label> actualTags); static boolean somePairsPresent(List<Label> expectedTags, List<Label> actualTags); static final String OR_OPERAND; static final String AND_OPERAND; static final String LABEL_QUERY_PARAM; static final String LABEL_OP_QUERY_PARAM; }### Answer:
@Test public void testGenerate3Pairs() { String tagQuery = "k1=v1,k2=v2,k3=v3"; List<Label> pairs = LabelUtils.generatePairs(tagQuery); assertEquals(3, pairs.size()); assertTrue(pairs.contains(new Label("k1", "v1"))); assertTrue(pairs.contains(new Label("k2", "v2"))); assertTrue(pairs.contains(new Label("k3", "v3"))); }
@Test public void testGenerate1Pair() { String tagQuery = "k1=v1"; List<Label> pairs = LabelUtils.generatePairs(tagQuery); assertEquals(1, pairs.size()); assertTrue(pairs.contains(new Label("k1", "v1"))); }
@Test public void testGeneratePairNull() { String tagQuery = null; List<Label> pairs = LabelUtils.generatePairs(tagQuery); assertEquals(0, pairs.size()); }
@Test public void testGeneratePairMalformed() { String tagQuery = "k1="; List<Label> pairs = LabelUtils.generatePairs(tagQuery); assertEquals(0, pairs.size()); }
@Test public void testGeneratePairPartialMalformed() { String tagQuery = "k1=,k2=v2"; List<Label> pairs = LabelUtils.generatePairs(tagQuery); assertEquals(1, pairs.size()); assertEquals(new Label("k2", "v2"), pairs.get(0)); }