1
+ // Copyright (c) 2019 Pivotal Software, Inc. All rights reserved.
2
+ //
3
+ // This software, the RabbitMQ Java client library, is triple-licensed under the
4
+ // Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5
+ // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6
+ // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7
+ // please see LICENSE-APACHE2.
8
+ //
9
+ // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10
+ // either express or implied. See the LICENSE file for specific language governing
11
+ // rights and limitations of this software.
12
+ //
13
+ // If you have any questions regarding licensing, please contact us at
14
+
15
+
1
16
package com .rabbitmq .client .impl ;
2
17
3
18
import org .junit .Test ;
4
19
5
- import java .io .DataOutputStream ;
6
- import java .io .IOException ;
7
- import java .io .OutputStream ;
20
+ import java .io .*;
8
21
import java .math .BigDecimal ;
9
22
import java .math .BigInteger ;
10
23
24
+ import static org .assertj .core .api .Assertions .assertThat ;
25
+
11
26
public class ValueWriterTest {
12
- @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeBigDecimalShouldFail ()
13
- throws IOException {
27
+
28
+ @ Test (expected = IllegalArgumentException .class )
29
+ public void writingOverlyLargeBigDecimalShouldFail ()
30
+ throws IOException {
14
31
15
32
OutputStream outputStream = new OutputStream () {
16
33
@ Override
@@ -26,8 +43,9 @@ public void write(int b) {
26
43
27
44
}
28
45
29
- @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeScaleInBigDecimalShouldFail ()
30
- throws IOException {
46
+ @ Test (expected = IllegalArgumentException .class )
47
+ public void writingOverlyLargeScaleInBigDecimalShouldFail ()
48
+ throws IOException {
31
49
32
50
OutputStream outputStream = new OutputStream () {
33
51
@ Override
@@ -41,4 +59,16 @@ public void write(int b) {
41
59
42
60
valueWriter .writeFieldValue (new BigDecimal (BigInteger .ONE , 500 ));
43
61
}
62
+
63
+ @ Test
64
+ public void bigDecimalWrittenAndReadMatches () throws IOException {
65
+ BigDecimal value = new BigDecimal (BigInteger .valueOf (56 ), 3 );
66
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
67
+ DataOutputStream dataOutputStream = new DataOutputStream (outputStream );
68
+ ValueWriter valueWriter = new ValueWriter (dataOutputStream );
69
+ valueWriter .writeFieldValue (value );
70
+
71
+ BigDecimal read = (BigDecimal ) ValueReader .readFieldValue (new DataInputStream (new ByteArrayInputStream (outputStream .toByteArray ())));
72
+ assertThat (read ).isEqualTo (value );
73
+ }
44
74
}
0 commit comments