Skip to content

Commit 1332277

Browse files
committed
Fix tests
The behavior has changed with codehaus-plexus/plexus-utils#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.
1 parent 0bcfeb7 commit 1332277

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void testShouldPerformSelfOverrideAtTopLevel()
153153
* <p>testShouldMergeValuesAtTopLevelByDefault.</p>
154154
*/
155155
@Test
156-
public void testShouldMergeValuesAtTopLevelByDefault()
156+
public void testShouldNotMergeValuesAtTopLevelByDefault()
157157
{
158158
// create the dominant DOM
159159
Xpp3Dom t1 = new Xpp3Dom( "top" );
@@ -172,15 +172,15 @@ public void testShouldMergeValuesAtTopLevelByDefault()
172172
// this is still 2, since we're not using the merge-control attribute.
173173
assertEquals( 2, result.getAttributeNames().length );
174174

175-
assertEquals( result.getValue(), t2.getValue() );
176-
assertEquals( "t2top", result.getInputLocation() );
175+
assertEquals( result.getValue(), t1.getValue() );
176+
assertEquals( "t1top", result.getInputLocation() );
177177
}
178178

179179
/**
180180
* <p>testShouldMergeValuesAtTopLevel.</p>
181181
*/
182182
@Test
183-
public void testShouldMergeValuesAtTopLevel()
183+
public void testShouldNotMergeValues()
184184
{
185185
// create the dominant DOM
186186
Xpp3Dom t1 = new Xpp3Dom( "top" );
@@ -197,7 +197,7 @@ public void testShouldMergeValuesAtTopLevel()
197197
Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( t1, t2 );
198198

199199
assertEquals( 3, result.getAttributeNames().length );
200-
assertEquals( result.getValue(), t2.getValue() );
200+
assertNull( result.getValue(), t1.getValue() );
201201
}
202202

203203
/**

src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java

+52
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNull;
2021

2122
import java.io.IOException;
2223
import java.io.StringReader;
@@ -150,6 +151,57 @@ public void testIsNotEmptyNegatesIsEmpty()
150151
assertEquals( !Xpp3DomUtils.isEmpty( "someValue" ), Xpp3DomUtils.isNotEmpty( "someValue" ) );
151152
}
152153

154+
/**
155+
* <p>testShouldMergeValuesAtTopLevelByDefault.</p>
156+
*/
157+
@Test
158+
public void testShouldNotMergeValuesAtTopLevelByDefault()
159+
{
160+
// create the dominant DOM
161+
Xpp3Dom t1 = new Xpp3Dom( "top" );
162+
t1.setAttribute( "attr", "value" );
163+
t1.setInputLocation( "t1top" );
164+
165+
// create the recessive DOM
166+
Xpp3Dom t2 = new Xpp3Dom( "top" );
167+
t2.setAttribute( "attr2", "value2" );
168+
t2.setValue( "t2Value" );
169+
t2.setInputLocation( "t2top" );
170+
171+
// merge and check results.
172+
Xpp3Dom result = Xpp3DomUtils.mergeXpp3Dom( t1, t2 );
173+
174+
// this is still 2, since we're not using the merge-control attribute.
175+
assertEquals( 2, result.getAttributeNames().length );
176+
177+
assertEquals( result.getValue(), t1.getValue() );
178+
assertEquals( "t1top", result.getInputLocation() );
179+
}
180+
181+
/**
182+
* <p>testShouldMergeValuesAtTopLevel.</p>
183+
*/
184+
@Test
185+
public void testShouldNotMergeValues()
186+
{
187+
// create the dominant DOM
188+
Xpp3Dom t1 = new Xpp3Dom( "top" );
189+
t1.setAttribute( "attr", "value" );
190+
191+
t1.setAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_MERGE );
192+
193+
// create the recessive DOM
194+
Xpp3Dom t2 = new Xpp3Dom( "top" );
195+
t2.setAttribute( "attr2", "value2" );
196+
t2.setValue( "t2Value" );
197+
198+
// merge and check results.
199+
Xpp3Dom result = Xpp3DomUtils.mergeXpp3Dom( t1, t2 );
200+
201+
assertEquals( 3, result.getAttributeNames().length );
202+
assertNull( result.getValue(), t1.getValue() );
203+
}
204+
153205
private static class FixedInputLocationBuilder
154206
implements Xpp3DomBuilder.InputLocationBuilder
155207
{

0 commit comments

Comments
 (0)