From 44c327d1a36f3a83c9bf20bf9c8e72363e005fb6 Mon Sep 17 00:00:00 2001 From: David Morley Date: Mon, 11 Apr 2016 05:26:22 -0500 Subject: [PATCH] Add expected exception handling to test --- .../test/XStreamJsonHierarchicalTest.java | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/xstream/src/test/java/com/baeldung/test/XStreamJsonHierarchicalTest.java b/xstream/src/test/java/com/baeldung/test/XStreamJsonHierarchicalTest.java index f92faa7196..1e71cb7066 100644 --- a/xstream/src/test/java/com/baeldung/test/XStreamJsonHierarchicalTest.java +++ b/xstream/src/test/java/com/baeldung/test/XStreamJsonHierarchicalTest.java @@ -1,45 +1,44 @@ package com.baeldung.test; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - import com.baeldung.initializer.SimpleXstreamInitializer; import com.baeldung.pojo.ContactDetails; import com.baeldung.pojo.Customer; import com.baeldung.utility.SimpleDataGeneration; import com.thoughtworks.xstream.XStream; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; public class XStreamJsonHierarchicalTest { - private Customer customer = null; - private String dataJson = null; - private XStream xstream = null; + private Customer customer = null; + private String dataJson = null; + private XStream xstream = null; - @Before - public void dataSetup() { - SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); - xstream = simpleXstreamInitializer.getXstreamJsonHierarchicalInstance(); - xstream.processAnnotations(Customer.class); - } + @Before + public void dataSetup() { + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamJsonHierarchicalInstance(); + xstream.processAnnotations(Customer.class); + } - @Test - public void convertObjectToJson() { - customer = SimpleDataGeneration.generateData(); - xstream.alias("customer", Customer.class); - xstream.alias("contactDetails", ContactDetails.class); - xstream.aliasField("fn", Customer.class, "firstName"); - dataJson = xstream.toXML(customer); - System.out.println(dataJson); - Assert.assertNotNull(dataJson); - } + @Test + public void convertObjectToJson() { + customer = SimpleDataGeneration.generateData(); + xstream.alias("customer", Customer.class); + xstream.alias("contactDetails", ContactDetails.class); + xstream.aliasField("fn", Customer.class, "firstName"); + dataJson = xstream.toXML(customer); + System.out.println(dataJson); + Assert.assertNotNull(dataJson); + } - @Test - public void convertJsonToObject() { - customer = SimpleDataGeneration.generateData(); - dataJson = xstream.toXML(customer); - // customer = (Customer) xstream.fromXML(dataJson); - // Assert.assertNotNull(customer); - } + @Test(expected = UnsupportedOperationException.class) + public void convertJsonToObject() { + customer = SimpleDataGeneration.generateData(); + dataJson = xstream.toXML(customer); + customer = (Customer) xstream.fromXML(dataJson); + Assert.assertNotNull(customer); + } }