AbstractConfig implements Serializable { protected static void appendParameters(Map<String, String> parameters, Object config) { appendParameters(parameters, config, null); }  @Parameter(excluded = true) String getId(); void setId(String id); @Override String toString();  }
@Test public void testAppendParameters1() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("default.num", "one"); parameters.put("num", "ONE"); AbstractConfig.appendParameters(parameters, new ParameterConfig(1, "hello/world", 30, "password"), "prefix"); TestCase.assertEquals("one", parameters.get("prefix.key.1")); TestCase.assertEquals("two", parameters.get("prefix.key.2")); TestCase.assertEquals("ONE,one,1", parameters.get("prefix.num")); TestCase.assertEquals("hello%2Fworld", parameters.get("prefix.naming")); TestCase.assertEquals("30", parameters.get("prefix.age")); TestCase.assertFalse(parameters.containsKey("prefix.key-2")); TestCase.assertFalse(parameters.containsKey("prefix.secret")); }
@Test(expected = IllegalStateException.class) public void testAppendParameters2() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); AbstractConfig.appendParameters(parameters, new ParameterConfig()); }
@Test public void testAppendParameters3() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); AbstractConfig.appendParameters(parameters, null); TestCase.assertTrue(parameters.isEmpty()); }
@Test public void testAppendParameters4() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); AbstractConfig.appendParameters(parameters, new ParameterConfig(1, "hello/world", 30, "password")); TestCase.assertEquals("one", parameters.get("key.1")); TestCase.assertEquals("two", parameters.get("key.2")); TestCase.assertEquals("1", parameters.get("num")); TestCase.assertEquals("hello%2Fworld", parameters.get("naming")); TestCase.assertEquals("30", parameters.get("age")); }