Add expected exception handling to test
This commit is contained in:
parent
ab3f68f1c2
commit
44c327d1a3
|
@ -1,45 +1,44 @@
|
||||||
package com.baeldung.test;
|
package com.baeldung.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.baeldung.initializer.SimpleXstreamInitializer;
|
import com.baeldung.initializer.SimpleXstreamInitializer;
|
||||||
import com.baeldung.pojo.ContactDetails;
|
import com.baeldung.pojo.ContactDetails;
|
||||||
import com.baeldung.pojo.Customer;
|
import com.baeldung.pojo.Customer;
|
||||||
import com.baeldung.utility.SimpleDataGeneration;
|
import com.baeldung.utility.SimpleDataGeneration;
|
||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class XStreamJsonHierarchicalTest {
|
public class XStreamJsonHierarchicalTest {
|
||||||
|
|
||||||
private Customer customer = null;
|
private Customer customer = null;
|
||||||
private String dataJson = null;
|
private String dataJson = null;
|
||||||
private XStream xstream = null;
|
private XStream xstream = null;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void dataSetup() {
|
public void dataSetup() {
|
||||||
SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer();
|
SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer();
|
||||||
xstream = simpleXstreamInitializer.getXstreamJsonHierarchicalInstance();
|
xstream = simpleXstreamInitializer.getXstreamJsonHierarchicalInstance();
|
||||||
xstream.processAnnotations(Customer.class);
|
xstream.processAnnotations(Customer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertObjectToJson() {
|
public void convertObjectToJson() {
|
||||||
customer = SimpleDataGeneration.generateData();
|
customer = SimpleDataGeneration.generateData();
|
||||||
xstream.alias("customer", Customer.class);
|
xstream.alias("customer", Customer.class);
|
||||||
xstream.alias("contactDetails", ContactDetails.class);
|
xstream.alias("contactDetails", ContactDetails.class);
|
||||||
xstream.aliasField("fn", Customer.class, "firstName");
|
xstream.aliasField("fn", Customer.class, "firstName");
|
||||||
dataJson = xstream.toXML(customer);
|
dataJson = xstream.toXML(customer);
|
||||||
System.out.println(dataJson);
|
System.out.println(dataJson);
|
||||||
Assert.assertNotNull(dataJson);
|
Assert.assertNotNull(dataJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
public void convertJsonToObject() {
|
public void convertJsonToObject() {
|
||||||
customer = SimpleDataGeneration.generateData();
|
customer = SimpleDataGeneration.generateData();
|
||||||
dataJson = xstream.toXML(customer);
|
dataJson = xstream.toXML(customer);
|
||||||
// customer = (Customer) xstream.fromXML(dataJson);
|
customer = (Customer) xstream.fromXML(dataJson);
|
||||||
// Assert.assertNotNull(customer);
|
Assert.assertNotNull(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue