public void testCopyHeader() throws Exception {
Field f1 = DefaultFieldParser.parse("name1: value1");
Field f2 = DefaultFieldParser.parse("name2: value");
Field f3 = DefaultFieldParser.parse("name1: value2");
Header original = new HeaderImpl();
original.addField(f1);
original.addField(f2);
original.addField(f3);
DefaultMessageBuilder builder = new DefaultMessageBuilder();
Header copy = builder.copy(original);
// copy must have same fields as original
assertEquals(Arrays.asList(f1, f2, f3), copy.getFields());
assertEquals(Arrays.asList(f1, f3), copy.getFields("name1"));
// modify original
original.removeFields("name1");
assertEquals(Arrays.asList(f2), original.getFields());
// copy may not be affected
assertEquals(Arrays.asList(f1, f2, f3), copy.getFields());
assertEquals(Arrays.asList(f1, f3), copy.getFields("name1"));
}