1 /*
2  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package test.java.math.RoundingMode;
24 
25 /*
26  * @test
27  * @bug 4851776 4891522 4905335
28  * @summary Basic tests for the RoundingMode class.
29  * @author Joseph D. Darcy
30  */
31 
32 import java.math.RoundingMode;
33 import java.math.BigDecimal;
34 
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37 
38 // Android-changed: Replace error throws with asserts.
39 public class RoundingModeTests {
40 
41     @Test
testRoundingMode()42     public void testRoundingMode() {
43 
44         // For each member of the family, make sure
45         // rm == valueOf(rm.toString())
46 
47         for(RoundingMode rm: RoundingMode.values()) {
48             Assert.assertEquals(RoundingMode.valueOf(rm.toString()), rm,
49                     "Bad roundtrip conversion of " + rm);
50         }
51 
52         // Test that mapping of old integers to new values is correct
53         Assert.assertEquals(RoundingMode.CEILING, RoundingMode.valueOf(BigDecimal.ROUND_CEILING),
54                 "Bad mapping for ROUND_CEILING");
55 
56         Assert.assertEquals(RoundingMode.DOWN, RoundingMode.valueOf(BigDecimal.ROUND_DOWN),
57                 "Bad mapping for ROUND_DOWN");
58 
59         Assert.assertEquals(RoundingMode.FLOOR, RoundingMode.valueOf(BigDecimal.ROUND_FLOOR),
60                 "Bad mapping for ROUND_FLOOR");
61 
62         Assert.assertEquals(RoundingMode.HALF_DOWN, RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN),
63                 "Bad mapping for ROUND_HALF_DOWN");
64 
65         Assert.assertEquals(RoundingMode.HALF_EVEN, RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN),
66                 "Bad mapping for ROUND_HALF_EVEN");
67 
68         Assert.assertEquals(RoundingMode.HALF_UP, RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP),
69                 "Bad mapping for ROUND_HALF_UP");
70 
71         Assert.assertEquals(RoundingMode.UNNECESSARY, RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY),
72                 "Bad mapping for ROUND_UNNECESSARY");
73     }
74 }
75