1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import java .io .ByteArrayOutputStream ;
25
25
import java .io .ObjectInputStream ;
26
26
import java .io .ObjectOutputStream ;
27
+ import java .nio .charset .StandardCharsets ;
28
+ import java .util .List ;
27
29
28
30
import org .junit .jupiter .api .Test ;
29
31
33
35
/**
34
36
* @author Mark Fisher
35
37
* @author Gary Russell
38
+ * @author Artem Bilan
36
39
*/
37
40
public class SimpleMessageConverterTests extends AllowedListDeserializingMessageConverterTests {
38
41
39
42
@ Test
40
- public void bytesAsDefaultMessageBodyType () throws Exception {
43
+ public void bytesAsDefaultMessageBodyType () {
41
44
SimpleMessageConverter converter = new SimpleMessageConverter ();
42
45
Message message = new Message ("test" .getBytes (), new MessageProperties ());
43
46
Object result = converter .fromMessage (message );
44
47
assertThat (result .getClass ()).isEqualTo (byte [].class );
45
- assertThat (new String ((byte []) result , "UTF-8" )).isEqualTo ("test" );
48
+ assertThat (new String ((byte []) result , StandardCharsets . UTF_8 )).isEqualTo ("test" );
46
49
}
47
50
48
51
@ Test
49
- public void noMessageIdByDefault () throws Exception {
52
+ public void noMessageIdByDefault () {
50
53
SimpleMessageConverter converter = new SimpleMessageConverter ();
51
54
Message message = converter .toMessage ("foo" , null );
52
55
assertThat (message .getMessageProperties ().getMessageId ()).isNull ();
53
56
}
54
57
55
58
@ Test
56
- public void optionalMessageId () throws Exception {
59
+ public void optionalMessageId () {
57
60
SimpleMessageConverter converter = new SimpleMessageConverter ();
58
61
converter .setCreateMessageIds (true );
59
62
Message message = converter .toMessage ("foo" , null );
@@ -87,6 +90,7 @@ public void messageToBytes() {
87
90
@ Test
88
91
public void messageToSerializedObject () throws Exception {
89
92
SimpleMessageConverter converter = new SimpleMessageConverter ();
93
+ converter .setAllowedListPatterns (List .of ("*" ));
90
94
MessageProperties properties = new MessageProperties ();
91
95
properties .setContentType (MessageProperties .CONTENT_TYPE_SERIALIZED_OBJECT );
92
96
ByteArrayOutputStream byteStream = new ByteArrayOutputStream ();
@@ -114,7 +118,7 @@ public void stringToMessage() throws Exception {
114
118
}
115
119
116
120
@ Test
117
- public void bytesToMessage () throws Exception {
121
+ public void bytesToMessage () {
118
122
SimpleMessageConverter converter = new SimpleMessageConverter ();
119
123
Message message = converter .toMessage (new byte [] { 1 , 2 , 3 }, new MessageProperties ());
120
124
String contentType = message .getMessageProperties ().getContentType ();
@@ -140,7 +144,7 @@ public void serializedObjectToMessage() throws Exception {
140
144
}
141
145
142
146
@ Test
143
- public void messageConversionExceptionForClassNotFound () throws Exception {
147
+ public void messageConversionExceptionForClassNotFound () {
144
148
SimpleMessageConverter converter = new SimpleMessageConverter ();
145
149
TestBean testBean = new TestBean ("foo" );
146
150
Message message = converter .toMessage (testBean , new MessageProperties ());
@@ -163,7 +167,8 @@ class Foo {
163
167
fail ("Expected exception" );
164
168
}
165
169
catch (IllegalArgumentException e ) {
166
- assertThat (e .getMessage ()).contains ("SimpleMessageConverter only supports String, byte[] and Serializable payloads, received:" );
170
+ assertThat (e .getMessage ())
171
+ .contains ("SimpleMessageConverter only supports String, byte[] and Serializable payloads, received:" );
167
172
}
168
173
}
169
174
0 commit comments