Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
The behavior has changed with #216 but plexus-utils contains duplicate merge code in Xpp3Dom and Xpp3DomUtils and the two pieces have divered.  This duplication is removed by the PR by switching to the XmlNode implementation in both cases, but we now need to fix the expectations.
  • Loading branch information
gnodet committed Apr 5, 2023
1 parent 0bcfeb7 commit 1332277
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java
Expand Up @@ -153,7 +153,7 @@ public void testShouldPerformSelfOverrideAtTopLevel()
* <p>testShouldMergeValuesAtTopLevelByDefault.</p>
*/
@Test
public void testShouldMergeValuesAtTopLevelByDefault()
public void testShouldNotMergeValuesAtTopLevelByDefault()
{
// create the dominant DOM
Xpp3Dom t1 = new Xpp3Dom( "top" );
Expand All @@ -172,15 +172,15 @@ public void testShouldMergeValuesAtTopLevelByDefault()
// this is still 2, since we're not using the merge-control attribute.
assertEquals( 2, result.getAttributeNames().length );

assertEquals( result.getValue(), t2.getValue() );
assertEquals( "t2top", result.getInputLocation() );
assertEquals( result.getValue(), t1.getValue() );
assertEquals( "t1top", result.getInputLocation() );
}

/**
* <p>testShouldMergeValuesAtTopLevel.</p>
*/
@Test
public void testShouldMergeValuesAtTopLevel()
public void testShouldNotMergeValues()
{
// create the dominant DOM
Xpp3Dom t1 = new Xpp3Dom( "top" );
Expand All @@ -197,7 +197,7 @@ public void testShouldMergeValuesAtTopLevel()
Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2 );

assertEquals( 3, result.getAttributeNames().length );
assertEquals( result.getValue(), t2.getValue() );
assertNull( result.getValue(), t1.getValue() );
}

/**
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java
Expand Up @@ -17,6 +17,7 @@
*/

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.io.StringReader;
Expand Down Expand Up @@ -150,6 +151,57 @@ public void testIsNotEmptyNegatesIsEmpty()
assertEquals( !Xpp3DomUtils.isEmpty( "someValue" ), Xpp3DomUtils.isNotEmpty( "someValue" ) );
}

/**
* <p>testShouldMergeValuesAtTopLevelByDefault.</p>
*/
@Test
public void testShouldNotMergeValuesAtTopLevelByDefault()
{
// create the dominant DOM
Xpp3Dom t1 = new Xpp3Dom( "top" );
t1.setAttribute( "attr", "value" );
t1.setInputLocation( "t1top" );

// create the recessive DOM
Xpp3Dom t2 = new Xpp3Dom( "top" );
t2.setAttribute( "attr2", "value2" );
t2.setValue( "t2Value" );
t2.setInputLocation( "t2top" );

// merge and check results.
Xpp3Dom result = Xpp3DomUtils.mergeXpp3Dom( t1, t2 );

// this is still 2, since we're not using the merge-control attribute.
assertEquals( 2, result.getAttributeNames().length );

assertEquals( result.getValue(), t1.getValue() );
assertEquals( "t1top", result.getInputLocation() );
}

/**
* <p>testShouldMergeValuesAtTopLevel.</p>
*/
@Test
public void testShouldNotMergeValues()
{
// create the dominant DOM
Xpp3Dom t1 = new Xpp3Dom( "top" );
t1.setAttribute( "attr", "value" );

t1.setAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_MERGE );

// create the recessive DOM
Xpp3Dom t2 = new Xpp3Dom( "top" );
t2.setAttribute( "attr2", "value2" );
t2.setValue( "t2Value" );

// merge and check results.
Xpp3Dom result = Xpp3DomUtils.mergeXpp3Dom( t1, t2 );

assertEquals( 3, result.getAttributeNames().length );
assertNull( result.getValue(), t1.getValue() );
}

private static class FixedInputLocationBuilder
implements Xpp3DomBuilder.InputLocationBuilder
{
Expand Down

0 comments on commit 1332277

Please sign in to comment.