Skip to content

Commit 44c327d

Browse files
committed
Add expected exception handling to test
1 parent ab3f68f commit 44c327d

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
package com.baeldung.test;
22

3-
import org.junit.Assert;
4-
import org.junit.Before;
5-
import org.junit.Test;
6-
73
import com.baeldung.initializer.SimpleXstreamInitializer;
84
import com.baeldung.pojo.ContactDetails;
95
import com.baeldung.pojo.Customer;
106
import com.baeldung.utility.SimpleDataGeneration;
117
import com.thoughtworks.xstream.XStream;
8+
import org.junit.Assert;
9+
import org.junit.Before;
10+
import org.junit.Test;
1211

1312
public class XStreamJsonHierarchicalTest {
1413

15-
private Customer customer = null;
16-
private String dataJson = null;
17-
private XStream xstream = null;
18-
19-
@Before
20-
public void dataSetup() {
21-
SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer();
22-
xstream = simpleXstreamInitializer.getXstreamJsonHierarchicalInstance();
23-
xstream.processAnnotations(Customer.class);
24-
}
25-
26-
@Test
27-
public void convertObjectToJson() {
28-
customer = SimpleDataGeneration.generateData();
29-
xstream.alias("customer", Customer.class);
30-
xstream.alias("contactDetails", ContactDetails.class);
31-
xstream.aliasField("fn", Customer.class, "firstName");
32-
dataJson = xstream.toXML(customer);
33-
System.out.println(dataJson);
34-
Assert.assertNotNull(dataJson);
35-
}
36-
37-
@Test
38-
public void convertJsonToObject() {
39-
customer = SimpleDataGeneration.generateData();
40-
dataJson = xstream.toXML(customer);
41-
// customer = (Customer) xstream.fromXML(dataJson);
42-
// Assert.assertNotNull(customer);
43-
}
14+
private Customer customer = null;
15+
private String dataJson = null;
16+
private XStream xstream = null;
17+
18+
@Before
19+
public void dataSetup() {
20+
SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer();
21+
xstream = simpleXstreamInitializer.getXstreamJsonHierarchicalInstance();
22+
xstream.processAnnotations(Customer.class);
23+
}
24+
25+
@Test
26+
public void convertObjectToJson() {
27+
customer = SimpleDataGeneration.generateData();
28+
xstream.alias("customer", Customer.class);
29+
xstream.alias("contactDetails", ContactDetails.class);
30+
xstream.aliasField("fn", Customer.class, "firstName");
31+
dataJson = xstream.toXML(customer);
32+
System.out.println(dataJson);
33+
Assert.assertNotNull(dataJson);
34+
}
35+
36+
@Test(expected = UnsupportedOperationException.class)
37+
public void convertJsonToObject() {
38+
customer = SimpleDataGeneration.generateData();
39+
dataJson = xstream.toXML(customer);
40+
customer = (Customer) xstream.fromXML(dataJson);
41+
Assert.assertNotNull(customer);
42+
}
4443

4544
}

0 commit comments

Comments
 (0)