|
17 | 17 | */
|
18 | 18 |
|
19 | 19 | import static org.junit.Assert.assertEquals;
|
| 20 | +import static org.junit.Assert.assertNull; |
20 | 21 |
|
21 | 22 | import java.io.IOException;
|
22 | 23 | import java.io.StringReader;
|
@@ -150,6 +151,57 @@ public void testIsNotEmptyNegatesIsEmpty()
|
150 | 151 | assertEquals( !Xpp3DomUtils.isEmpty( "someValue" ), Xpp3DomUtils.isNotEmpty( "someValue" ) );
|
151 | 152 | }
|
152 | 153 |
|
| 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 | + |
153 | 205 | private static class FixedInputLocationBuilder
|
154 | 206 | implements Xpp3DomBuilder.InputLocationBuilder
|
155 | 207 | {
|
|
0 commit comments