Skip to content

Commit de7ff55

Browse files
committed
Polishing
1 parent 24adc7d commit de7ff55

File tree

3 files changed

+58
-72
lines changed

3 files changed

+58
-72
lines changed

spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,28 @@
1616

1717
package org.springframework.oxm.xstream;
1818

19-
import com.thoughtworks.xstream.converters.Converter;
19+
import java.io.ByteArrayOutputStream;
20+
import java.io.Reader;
21+
import java.io.StringReader;
22+
import java.io.StringWriter;
23+
import java.io.Writer;
24+
import java.util.Arrays;
25+
import java.util.Collections;
26+
import java.util.HashMap;
27+
import java.util.Map;
28+
import java.util.concurrent.atomic.AtomicInteger;
29+
import javax.xml.parsers.DocumentBuilder;
30+
import javax.xml.parsers.DocumentBuilderFactory;
31+
import javax.xml.stream.XMLEventWriter;
32+
import javax.xml.stream.XMLOutputFactory;
33+
import javax.xml.stream.XMLStreamWriter;
34+
import javax.xml.transform.Result;
35+
import javax.xml.transform.Source;
36+
import javax.xml.transform.dom.DOMResult;
37+
import javax.xml.transform.sax.SAXResult;
38+
import javax.xml.transform.stream.StreamResult;
39+
import javax.xml.transform.stream.StreamSource;
40+
2041
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
2142
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
2243
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
@@ -26,7 +47,6 @@
2647
import org.junit.Ignore;
2748
import org.junit.Test;
2849
import org.mockito.InOrder;
29-
import org.springframework.util.xml.StaxUtils;
3050
import org.w3c.dom.Document;
3151
import org.w3c.dom.Element;
3252
import org.w3c.dom.Node;
@@ -36,37 +56,11 @@
3656
import org.xmlunit.builder.Input;
3757
import org.xmlunit.xpath.JAXPXPathEngine;
3858

39-
import javax.xml.parsers.DocumentBuilder;
40-
import javax.xml.parsers.DocumentBuilderFactory;
41-
import javax.xml.stream.XMLEventWriter;
42-
import javax.xml.stream.XMLOutputFactory;
43-
import javax.xml.stream.XMLStreamWriter;
44-
import javax.xml.transform.Result;
45-
import javax.xml.transform.Source;
46-
import javax.xml.transform.dom.DOMResult;
47-
import javax.xml.transform.sax.SAXResult;
48-
import javax.xml.transform.stream.StreamResult;
49-
import javax.xml.transform.stream.StreamSource;
50-
import java.io.ByteArrayOutputStream;
51-
import java.io.Reader;
52-
import java.io.StringReader;
53-
import java.io.StringWriter;
54-
import java.io.Writer;
55-
import java.util.Arrays;
56-
import java.util.Collections;
57-
import java.util.HashMap;
58-
import java.util.Map;
59-
import java.util.concurrent.atomic.AtomicInteger;
59+
import org.springframework.util.xml.StaxUtils;
6060

61-
import static org.junit.Assert.assertEquals;
62-
import static org.junit.Assert.assertNotNull;
63-
import static org.junit.Assert.assertThat;
64-
import static org.junit.Assert.assertTrue;
65-
import static org.mockito.BDDMockito.eq;
66-
import static org.mockito.BDDMockito.inOrder;
67-
import static org.mockito.BDDMockito.isA;
68-
import static org.mockito.BDDMockito.mock;
69-
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
61+
import static org.junit.Assert.*;
62+
import static org.mockito.BDDMockito.*;
63+
import static org.xmlunit.matchers.CompareMatcher.*;
7064

7165
/**
7266
* @author Arjen Poutsma
@@ -80,8 +74,9 @@ public class XStreamMarshallerTests {
8074

8175
private Flight flight;
8276

77+
8378
@Before
84-
public void createMarshaller() throws Exception {
79+
public void createMarshaller() {
8580
marshaller = new XStreamMarshaller();
8681
Map<String, String> aliases = new HashMap<>();
8782
aliases.put("flight", Flight.class.getName());
@@ -90,6 +85,7 @@ public void createMarshaller() throws Exception {
9085
flight.setFlightNumber(42L);
9186
}
9287

88+
9389
@Test
9490
public void marshalDOMResult() throws Exception {
9591
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
@@ -190,7 +186,7 @@ public void marshalStaxResultXMLEventWriter() throws Exception {
190186

191187
@Test
192188
public void converters() throws Exception {
193-
marshaller.setConverters(new Converter[]{new EncodedByteArrayConverter()});
189+
marshaller.setConverters(new EncodedByteArrayConverter());
194190
byte[] buf = new byte[]{0x1, 0x2};
195191
Writer writer = new StringWriter();
196192
marshaller.marshal(buf, new StreamResult(writer));
@@ -229,8 +225,7 @@ public void useAttributesForClassStringMap() throws Exception {
229225

230226
@Test
231227
public void useAttributesForClassStringListMap() throws Exception {
232-
marshaller
233-
.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber")));
228+
marshaller.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber")));
234229
Writer writer = new StringWriter();
235230
marshaller.marshal(flight, new StreamResult(writer));
236231
String expected = "<flight flightNumber=\"42\" />";
@@ -349,6 +344,7 @@ public void annotatedMarshalStreamResultWriter() throws Exception {
349344
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(expected));
350345
}
351346

347+
352348
private static void assertXpathExists(String xPathExpression, String inXMLString){
353349
Source source = Input.fromString(inXMLString).build();
354350
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source);

spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ public void matchesSpecific() throws Exception {
6363
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
6464

6565
checkTransactionProperties(tas, Object.class.getMethod("hashCode"),
66-
TransactionDefinition.PROPAGATION_REQUIRED);
66+
TransactionDefinition.PROPAGATION_REQUIRED);
6767
checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class),
68-
TransactionDefinition.PROPAGATION_MANDATORY);
68+
TransactionDefinition.PROPAGATION_MANDATORY);
6969
checkTransactionProperties(tas, Object.class.getMethod("wait"),
70-
TransactionDefinition.PROPAGATION_SUPPORTS);
70+
TransactionDefinition.PROPAGATION_SUPPORTS);
7171
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class),
72-
TransactionDefinition.PROPAGATION_SUPPORTS);
72+
TransactionDefinition.PROPAGATION_SUPPORTS);
7373
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class),
74-
TransactionDefinition.PROPAGATION_SUPPORTS);
74+
TransactionDefinition.PROPAGATION_SUPPORTS);
7575
checkTransactionProperties(tas, Object.class.getMethod("notify"),
76-
TransactionDefinition.PROPAGATION_SUPPORTS);
76+
TransactionDefinition.PROPAGATION_SUPPORTS);
7777
checkTransactionProperties(tas, Object.class.getMethod("notifyAll"),
78-
TransactionDefinition.PROPAGATION_REQUIRED);
78+
TransactionDefinition.PROPAGATION_REQUIRED);
7979
checkTransactionProperties(tas, Object.class.getMethod("toString"), -1);
8080
}
8181

@@ -85,21 +85,21 @@ public void matchesAll() throws Exception {
8585
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
8686

8787
checkTransactionProperties(tas, Object.class.getMethod("hashCode"),
88-
TransactionDefinition.PROPAGATION_REQUIRED);
88+
TransactionDefinition.PROPAGATION_REQUIRED);
8989
checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class),
90-
TransactionDefinition.PROPAGATION_REQUIRED);
90+
TransactionDefinition.PROPAGATION_REQUIRED);
9191
checkTransactionProperties(tas, Object.class.getMethod("wait"),
92-
TransactionDefinition.PROPAGATION_REQUIRED);
92+
TransactionDefinition.PROPAGATION_REQUIRED);
9393
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class),
94-
TransactionDefinition.PROPAGATION_REQUIRED);
94+
TransactionDefinition.PROPAGATION_REQUIRED);
9595
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class),
96-
TransactionDefinition.PROPAGATION_REQUIRED);
96+
TransactionDefinition.PROPAGATION_REQUIRED);
9797
checkTransactionProperties(tas, Object.class.getMethod("notify"),
98-
TransactionDefinition.PROPAGATION_REQUIRED);
98+
TransactionDefinition.PROPAGATION_REQUIRED);
9999
checkTransactionProperties(tas, Object.class.getMethod("notifyAll"),
100-
TransactionDefinition.PROPAGATION_REQUIRED);
100+
TransactionDefinition.PROPAGATION_REQUIRED);
101101
checkTransactionProperties(tas, Object.class.getMethod("toString"),
102-
TransactionDefinition.PROPAGATION_REQUIRED);
102+
TransactionDefinition.PROPAGATION_REQUIRED);
103103
}
104104

105105
private void checkTransactionProperties(TransactionAttributeSource tas, Method method, int propagationBehavior) {

spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,67 +40,57 @@ public class TransactionAttributeSourceTests {
4040
@Test
4141
public void matchAlwaysTransactionAttributeSource() throws Exception {
4242
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
43-
TransactionAttribute ta = tas.getTransactionAttribute(
44-
Object.class.getMethod("hashCode"), null);
43+
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
4544
assertNotNull(ta);
4645
assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior());
4746

4847
tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
49-
ta = tas.getTransactionAttribute(
50-
IOException.class.getMethod("getMessage"), IOException.class);
48+
ta = tas.getTransactionAttribute(IOException.class.getMethod("getMessage"), IOException.class);
5149
assertNotNull(ta);
5250
assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior());
5351
}
5452

5553
@Test
56-
public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName()
57-
throws NoSuchMethodException {
54+
public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName() throws Exception {
5855
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
5956
Properties attributes = new Properties();
6057
attributes.put("*ashCode", "PROPAGATION_REQUIRED");
6158
tas.setProperties(attributes);
62-
TransactionAttribute ta = tas.getTransactionAttribute(
63-
Object.class.getMethod("hashCode"), null);
59+
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
6460
assertNotNull(ta);
6561
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
6662
}
6763

6864
@Test
69-
public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName()
70-
throws NoSuchMethodException {
65+
public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName() throws Exception {
7166
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
7267
Properties attributes = new Properties();
7368
attributes.put("hashCod*", "PROPAGATION_REQUIRED");
7469
tas.setProperties(attributes);
75-
TransactionAttribute ta = tas.getTransactionAttribute(
76-
Object.class.getMethod("hashCode"), null);
70+
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
7771
assertNotNull(ta);
7872
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
7973
}
8074

8175
@Test
82-
public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched()
83-
throws NoSuchMethodException {
76+
public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched() throws Exception {
8477
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
8578
Properties attributes = new Properties();
8679
attributes.put("*", "PROPAGATION_REQUIRED");
8780
attributes.put("hashCode", "PROPAGATION_MANDATORY");
8881
tas.setProperties(attributes);
89-
TransactionAttribute ta = tas.getTransactionAttribute(
90-
Object.class.getMethod("hashCode"), null);
82+
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
9183
assertNotNull(ta);
9284
assertEquals(TransactionDefinition.PROPAGATION_MANDATORY, ta.getPropagationBehavior());
9385
}
9486

9587
@Test
96-
public void nameMatchTransactionAttributeSourceWithEmptyMethodName()
97-
throws NoSuchMethodException {
88+
public void nameMatchTransactionAttributeSourceWithEmptyMethodName() throws Exception {
9889
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
9990
Properties attributes = new Properties();
10091
attributes.put("", "PROPAGATION_MANDATORY");
10192
tas.setProperties(attributes);
102-
TransactionAttribute ta = tas.getTransactionAttribute(
103-
Object.class.getMethod("hashCode"), null);
93+
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
10494
assertNull(ta);
10595
}
10696

0 commit comments

Comments
 (0)