Skip to content

Commit

Permalink
Fixed #17
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Mar 6, 2020
1 parent d6fbb35 commit d6c227e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This project was the following modules:
* Added new methods `EmailAddress.createOnDemand`
* `URLHelper.urlEncode` and `URLHelper.urlDecode` now uses `URLCodec`
* Deprecated `ICommonsIterable.forEach` in favour of `findAll`
* Fixed a bug in the cloning of `MapBasedNamespaceContext` (see [issue #17](https://github.com/phax/ph-commons/issues/17))
* v9.3.9 - 2019-12-11
* Made `ClassLoaderHelper.getResource` more robust
* Updated "mime-type-info.xml" list with shared-mime-info-spec 1.15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public MapBasedNamespaceContext (@Nullable final MapBasedNamespaceContext aOther
{
m_sDefaultNamespaceURI = aOther.m_sDefaultNamespaceURI;
m_aPrefix2NS.putAll (aOther.m_aPrefix2NS);
m_aNS2Prefix.putAll (aOther.m_aNS2Prefix);

// putAll is not enough here
for (final Map.Entry <String, ICommonsSet <String>> aEntry : aOther.m_aNS2Prefix.entrySet ())
m_aNS2Prefix.put (aEntry.getKey (), aEntry.getValue ().getClone ());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import javax.xml.XMLConstants;

import org.junit.Test;

import com.helger.commons.mock.CommonsTestHelper;
import com.helger.commons.state.EChange;

/**
* Test class for class {@link MapBasedNamespaceContext}.
Expand Down Expand Up @@ -91,4 +93,19 @@ public void testAll ()
CommonsTestHelper.testToStringImplementation (c);
CommonsTestHelper.testDefaultSerialization (c);
}

@Test
public void testCloneIssue17 ()
{
final MapBasedNamespaceContext aNSCtx = new MapBasedNamespaceContext ();
aNSCtx.addMapping ("p1", "urn:example1");
aNSCtx.addMapping ("p2", "urn:example2");
final MapBasedNamespaceContext aNSCtx2 = aNSCtx.getClone ();
// Remove from original
assertSame (EChange.CHANGED, aNSCtx.removeMapping ("p1"));
assertSame (EChange.UNCHANGED, aNSCtx.removeMapping ("p1"));
// Remove from clone
assertSame (EChange.CHANGED, aNSCtx2.removeMapping ("p1"));
assertSame (EChange.UNCHANGED, aNSCtx2.removeMapping ("p1"));
}
}

0 comments on commit d6c227e

Please sign in to comment.