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+
116package com .rabbitmq .client .impl ;
217
318import org .junit .Test ;
419
5- import java .io .DataOutputStream ;
6- import java .io .IOException ;
7- import java .io .OutputStream ;
20+ import java .io .*;
821import java .math .BigDecimal ;
922import java .math .BigInteger ;
1023
24+ import static org .assertj .core .api .Assertions .assertThat ;
25+
1126public 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 {
1431
1532 OutputStream outputStream = new OutputStream () {
1633 @ Override
@@ -26,8 +43,9 @@ public void write(int b) {
2643
2744 }
2845
29- @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeScaleInBigDecimalShouldFail ()
30- throws IOException {
46+ @ Test (expected = IllegalArgumentException .class )
47+ public void writingOverlyLargeScaleInBigDecimalShouldFail ()
48+ throws IOException {
3149
3250 OutputStream outputStream = new OutputStream () {
3351 @ Override
@@ -41,4 +59,16 @@ public void write(int b) {
4159
4260 valueWriter .writeFieldValue (new BigDecimal (BigInteger .ONE , 500 ));
4361 }
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+ }
4474}
0 commit comments