Skip to content

Commit

Permalink
Issues #38, #44, #45, #46, #47.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Dec 23, 2015
1 parent 73cc3f5 commit 9d5ef0e
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import junit.framework.TestCase;

import org.jvnet.jaxb2_commons.lang.CopyStrategy;
import org.jvnet.jaxb2_commons.lang.CopyTo;
import org.jvnet.jaxb2_commons.lang.CopyStrategy2;
import org.jvnet.jaxb2_commons.lang.CopyTo2;
import org.jvnet.jaxb2_commons.lang.JAXBCopyStrategy;
import org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;

public class CyclicTests extends TestCase {

public interface CopyToInstance extends CopyTo {
public interface CopyToInstance extends CopyTo2 {
}

public static class A implements CopyToInstance {
Expand All @@ -29,10 +29,11 @@ public Object copyTo(Object target) {
}

public Object copyTo(ObjectLocator locator, Object target,
CopyStrategy copyStrategy) {
CopyStrategy2 copyStrategy) {
final A that = (A) target;
that.b = (B) copyStrategy.copy(LocatorUtils.property(locator, "b",
this.b), this.b);
that.b = (B) copyStrategy.copy(
LocatorUtils.property(locator, "b", this.b), this.b,
this.b != null);
return that;
}

Expand All @@ -50,10 +51,11 @@ public Object copyTo(Object target) {
}

public Object copyTo(ObjectLocator locator, Object target,
CopyStrategy copyStrategy) {
CopyStrategy2 copyStrategy) {
final B that = (B) target;
that.a = (A) copyStrategy.copy(LocatorUtils.property(locator, "a",
this.a), this.a);
that.a = (A) copyStrategy.copy(
LocatorUtils.property(locator, "a", this.a), this.a,
this.a != null);
return that;
}
}
Expand All @@ -68,7 +70,8 @@ public void testCycle() throws Exception {
private Map<Object, Object> copies = new IdentityHashMap<Object, Object>();

@Override
public Object copy(ObjectLocator locator, Object object) {
public Object copy(ObjectLocator locator, Object object,
boolean objectSet) {
final Object existingCopy = copies.get(object);
if (existingCopy != null) {
return existingCopy;
Expand All @@ -80,7 +83,7 @@ public Object copy(ObjectLocator locator, Object object) {
source.copyTo(locator, newCopy, this);
return newCopy;
} else {
final Object newCopy = super.copy(locator, object);
final Object newCopy = super.copy(locator, object, objectSet);
copies.put(object, newCopy);
return newCopy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import junit.framework.Assert;
import org.junit.Assert;
import junit.framework.TestCase;

import org.apache.commons.io.FileUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,46 @@

import org.junit.Assert;
import org.junit.Test;
import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.lang.ToStringStrategy2;

public class GH37Test {

@Test
public void considersDefaultValues() {
public void considersDefaultValuesInMerge() {
final IssueGH37Type left = new IssueGH37Type();
final IssueGH37Type right = new IssueGH37Type();
final IssueGH37Type result = new IssueGH37Type();
result.mergeFrom(left, right);
Assert.assertTrue(result.isTestBoolean());
}

@Test
public void considersDefaultValuesInCopyTo() {
final IssueGH37Type original = new IssueGH37Type();
final IssueGH37Type copy = (IssueGH37Type) original.clone();
Assert.assertTrue(copy.isTestBoolean());
Assert.assertFalse(copy.isSetTestBoolean());
Assert.assertEquals(original, copy);
}

@Test
public void considersDefaultValuesInToString() {
final ToStringStrategy2 strategy = new JAXBToStringStrategy() {
@Override
public boolean isUseIdentityHashCode() {
return false;
}
};
IssueGH37Type a = new IssueGH37Type();
Assert.assertEquals(
"org.jvnet.jaxb2_commons.tests.issues.IssueGH37Type[testBoolean=true(default)]",
a.append(null, new StringBuilder(), strategy).toString());
IssueGH37Type b = new IssueGH37Type();
b.setTestBoolean(true);
Assert.assertEquals(
"org.jvnet.jaxb2_commons.tests.issues.IssueGH37Type[testBoolean=true]",
b.append(null, new StringBuilder(), strategy).toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import javax.xml.bind.annotation.XmlAnyElement;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Assert;

public class JIIB10Test extends TestCase {

public void testXmlAnyElementLax() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.jvnet.jaxb2_commons.tests.issues;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Assert;

public class JIIB14Test extends TestCase {

public void testIssueJIIB14() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import java.util.Arrays;
import java.util.List;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Assert;

public class JIIB20Test extends TestCase {

public void testException() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import javax.xml.bind.JAXBContext;

import junit.framework.Assert;
import org.junit.Assert;
import junit.framework.TestCase;

import org.jvnet.jaxb2_commons.lang.ContextUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jvnet.jaxb2_commons.tests.issues;

import junit.framework.Assert;
import org.junit.Assert;
import junit.framework.TestCase;

public class JIIB38Test extends TestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Arrays;

import junit.framework.Assert;
import org.junit.Assert;
import junit.framework.TestCase;

public class JIIB8Test extends TestCase {
Expand Down
8 changes: 6 additions & 2 deletions tests/superclass/b/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-test-superclass-a</artifactId>
</plugin>
</plugins>
<episodes>
<!--episodes>
<episode>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-test-superclass-a</artifactId>
</episode>
</episodes>
</episodes-->
</configuration>
</plugin>
</plugins>
Expand Down

0 comments on commit 9d5ef0e

Please # to comment.