diff --git a/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java index 6443dd25d2e..4f7e50c6f66 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java @@ -16,7 +16,28 @@ package org.springframework.oxm.xstream; -import com.thoughtworks.xstream.converters.Converter; +import java.io.ByteArrayOutputStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; @@ -26,7 +47,6 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.InOrder; -import org.springframework.util.xml.StaxUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -36,37 +56,11 @@ import org.xml.sax.ContentHandler; import org.xmlunit.builder.Input; import org.xmlunit.xpath.JAXPXPathEngine; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import java.io.ByteArrayOutputStream; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; +import org.springframework.util.xml.StaxUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.BDDMockito.eq; -import static org.mockito.BDDMockito.inOrder; -import static org.mockito.BDDMockito.isA; -import static org.mockito.BDDMockito.mock; -import static org.xmlunit.matchers.CompareMatcher.isSimilarTo; +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; +import static org.xmlunit.matchers.CompareMatcher.*; /** * @author Arjen Poutsma @@ -80,8 +74,9 @@ public class XStreamMarshallerTests { private Flight flight; + @Before - public void createMarshaller() throws Exception { + public void createMarshaller() { marshaller = new XStreamMarshaller(); Map aliases = new HashMap<>(); aliases.put("flight", Flight.class.getName()); @@ -90,6 +85,7 @@ public class XStreamMarshallerTests { flight.setFlightNumber(42L); } + @Test public void marshalDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); @@ -190,7 +186,7 @@ public class XStreamMarshallerTests { @Test public void converters() throws Exception { - marshaller.setConverters(new Converter[]{new EncodedByteArrayConverter()}); + marshaller.setConverters(new EncodedByteArrayConverter()); byte[] buf = new byte[]{0x1, 0x2}; Writer writer = new StringWriter(); marshaller.marshal(buf, new StreamResult(writer)); @@ -229,8 +225,7 @@ public class XStreamMarshallerTests { @Test public void useAttributesForClassStringListMap() throws Exception { - marshaller - .setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber"))); + marshaller.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber"))); Writer writer = new StringWriter(); marshaller.marshal(flight, new StreamResult(writer)); String expected = ""; @@ -349,6 +344,7 @@ public class XStreamMarshallerTests { assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(expected)); } + private static void assertXpathExists(String xPathExpression, String inXMLString){ Source source = Input.fromString(inXMLString).build(); Iterable nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source); diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java index f3ca7163533..2d9321c7b40 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java @@ -63,19 +63,19 @@ public class TransactionAttributeSourceEditorTests { TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); checkTransactionProperties(tas, Object.class.getMethod("hashCode"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class), - TransactionDefinition.PROPAGATION_MANDATORY); + TransactionDefinition.PROPAGATION_MANDATORY); checkTransactionProperties(tas, Object.class.getMethod("wait"), - TransactionDefinition.PROPAGATION_SUPPORTS); + TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class), - TransactionDefinition.PROPAGATION_SUPPORTS); + TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class), - TransactionDefinition.PROPAGATION_SUPPORTS); + TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("notify"), - TransactionDefinition.PROPAGATION_SUPPORTS); + TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("notifyAll"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("toString"), -1); } @@ -85,21 +85,21 @@ public class TransactionAttributeSourceEditorTests { TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); checkTransactionProperties(tas, Object.class.getMethod("hashCode"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("wait"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("notify"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("notifyAll"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("toString"), - TransactionDefinition.PROPAGATION_REQUIRED); + TransactionDefinition.PROPAGATION_REQUIRED); } private void checkTransactionProperties(TransactionAttributeSource tas, Method method, int propagationBehavior) { diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java index ade9b34bc57..a3cd1954744 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,67 +40,57 @@ public class TransactionAttributeSourceTests { @Test public void matchAlwaysTransactionAttributeSource() throws Exception { MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource(); - TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode"), null); + TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior()); tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS)); - ta = tas.getTransactionAttribute( - IOException.class.getMethod("getMessage"), IOException.class); + ta = tas.getTransactionAttribute(IOException.class.getMethod("getMessage"), IOException.class); assertNotNull(ta); assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior()); } @Test - public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName() - throws NoSuchMethodException { + public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName() throws Exception { NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource(); Properties attributes = new Properties(); attributes.put("*ashCode", "PROPAGATION_REQUIRED"); tas.setProperties(attributes); - TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode"), null); + TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); } @Test - public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName() - throws NoSuchMethodException { + public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName() throws Exception { NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource(); Properties attributes = new Properties(); attributes.put("hashCod*", "PROPAGATION_REQUIRED"); tas.setProperties(attributes); - TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode"), null); + TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); } @Test - public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched() - throws NoSuchMethodException { + public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched() throws Exception { NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource(); Properties attributes = new Properties(); attributes.put("*", "PROPAGATION_REQUIRED"); attributes.put("hashCode", "PROPAGATION_MANDATORY"); tas.setProperties(attributes); - TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode"), null); + TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertEquals(TransactionDefinition.PROPAGATION_MANDATORY, ta.getPropagationBehavior()); } @Test - public void nameMatchTransactionAttributeSourceWithEmptyMethodName() - throws NoSuchMethodException { + public void nameMatchTransactionAttributeSourceWithEmptyMethodName() throws Exception { NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource(); Properties attributes = new Properties(); attributes.put("", "PROPAGATION_MANDATORY"); tas.setProperties(attributes); - TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode"), null); + TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null); assertNull(ta); }