Skip to content

Commit 5cef8b3

Browse files
justin-curtis-lupull[bot]
authored andcommitted
8295000: java/util/Formatter/Basic test cleanup
Reviewed-by: bchristi, naoto, lancea
1 parent a20dcd8 commit 5cef8b3

20 files changed

+306
-107
lines changed

test/jdk/java/util/Formatter/Basic-X.java.template

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -229,22 +229,22 @@ public class Basic$Type$ extends Basic {
229229
#end[dec]
230230
#if[Byte]
231231
private static $type$ negate($type$ v) {
232-
return new $type$((byte) -v.byteValue());
232+
return (byte) -v.byteValue();
233233
}
234234
#end[Byte]
235235
#if[Short]
236236
private static $type$ negate($type$ v) {
237-
return new $type$((short) -v.shortValue());
237+
return (short) -v.shortValue();
238238
}
239239
#end[Short]
240240
#if[Integer]
241241
private static $type$ negate($type$ v) {
242-
return new $type$(-v.intValue());
242+
return -v.intValue();
243243
}
244244
#end[Integer]
245245
#if[Long]
246246
private static $type$ negate($type$ v) {
247-
return new $type$(-v.longValue());
247+
return -v.longValue();
248248
}
249249
#end[Long]
250250

@@ -284,19 +284,19 @@ public class Basic$Type$ extends Basic {
284284
#end[float]
285285
#if[Float]
286286
private static $type$ create(double v) {
287-
return new $type$(v);
287+
return (float) v;
288288
}
289289

290290
private static $type$ negate($type$ v) {
291-
return new $type$(-v.floatValue());
291+
return -v.floatValue();
292292
}
293293

294294
private static $type$ mult($type$ v, double mul) {
295-
return new $type$(v.floatValue() * (float) mul);
295+
return v.floatValue() * (float) mul;
296296
}
297297

298298
private static $type$ recip($type$ v) {
299-
return new $type$(1.0f / v.floatValue());
299+
return 1.0f / v.floatValue();
300300
}
301301
#end[Float]
302302
#if[double]
@@ -319,19 +319,19 @@ public class Basic$Type$ extends Basic {
319319
#end[double]
320320
#if[Double]
321321
private static $type$ create(double v) {
322-
return new $type$(v);
322+
return v;
323323
}
324324

325325
private static $type$ negate($type$ v) {
326-
return new $type$(-v.doubleValue());
326+
return -v.doubleValue();
327327
}
328328

329329
private static $type$ mult($type$ v, double mul) {
330-
return new $type$(v.doubleValue() * mul);
330+
return v.doubleValue() * mul;
331331
}
332332

333333
private static $type$ recip($type$ v) {
334-
return new $type$(1.0 / v.doubleValue());
334+
return 1.0 / v.doubleValue();
335335
}
336336
#end[Double]
337337

@@ -435,7 +435,7 @@ public class Basic$Type$ extends Basic {
435435
test("%-4c", "i ", 'i');
436436
test("%4C", " I", 'i');
437437
test("%-4C", "I ", 'i');
438-
test("%c", "i", new Character('i'));
438+
test("%c", "i", Character.valueOf('i'));
439439
test("%c", "H", (byte) 72);
440440
test("%c", "i", (short) 105);
441441
test("%c", "!", (int) 33);
@@ -493,7 +493,7 @@ public class Basic$Type$ extends Basic {
493493
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
494494
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
495495
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
496-
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
496+
tryCatch("%#s", FormatFlagsConversionMismatchException.class, (Object)null);
497497

498498
//---------------------------------------------------------------------
499499
// %h
@@ -521,11 +521,21 @@ public class Basic$Type$ extends Basic {
521521
tryCatch("%#g", FormatFlagsConversionMismatchException.class);
522522

523523
#if[dec]
524-
525524
#if[prim]
526525
$type$ minByte = Byte.MIN_VALUE; // -128
527526
#else[prim]
528-
$type$ minByte = new $type$(Byte.MIN_VALUE);
527+
#if[Short]
528+
$type$ minByte = (short) Byte.MIN_VALUE;
529+
#end[Short]
530+
#if[Byte]
531+
$type$ minByte = Byte.MIN_VALUE;
532+
#end[Byte]
533+
#if[Integer]
534+
$type$ minByte = (int) Byte.MIN_VALUE;
535+
#end[Integer]
536+
#if[Long]
537+
$type$ minByte = (long) Byte.MIN_VALUE;
538+
#end[Long]
529539
#end[prim]
530540

531541
//---------------------------------------------------------------------
@@ -886,9 +896,9 @@ public class Basic$Type$ extends Basic {
886896
//---------------------------------------------------------------------
887897
// %s - Float
888898
//---------------------------------------------------------------------
889-
$type$ one = new $type$(1.0f);
890-
$type$ ten = new $type$(10.0f);
891-
$type$ pi = new $type$(Math.PI);
899+
$type$ one = 1.0f;
900+
$type$ ten = 10.0f;
901+
$type$ pi = (float) Math.PI;
892902

893903
test("%s", "3.1415927", pi);
894904
#end[Float]
@@ -906,9 +916,9 @@ public class Basic$Type$ extends Basic {
906916
//---------------------------------------------------------------------
907917
// %s - Double
908918
//---------------------------------------------------------------------
909-
$type$ one = new $type$(1.0);
910-
$type$ ten = new $type$(10.0);
911-
$type$ pi = new $type$(Math.PI);
919+
$type$ one = 1.0d;
920+
$type$ ten = 10.0d;
921+
$type$ pi = (double) Math.PI;
912922

913923
test("%s", "3.141592653589793", pi);
914924
#end[Double]

test/jdk/java/util/Formatter/BasicBigDecimal.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -435,7 +435,7 @@ public static void test() {
435435
test("%-4c", "i ", 'i');
436436
test("%4C", " I", 'i');
437437
test("%-4C", "I ", 'i');
438-
test("%c", "i", new Character('i'));
438+
test("%c", "i", Character.valueOf('i'));
439439
test("%c", "H", (byte) 72);
440440
test("%c", "i", (short) 105);
441441
test("%c", "!", (int) 33);
@@ -493,7 +493,7 @@ public static void test() {
493493
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
494494
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
495495
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
496-
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
496+
tryCatch("%#s", FormatFlagsConversionMismatchException.class, (Object)null);
497497

498498
//---------------------------------------------------------------------
499499
// %h
@@ -851,6 +851,16 @@ public static void test() {
851851

852852

853853

854+
855+
856+
857+
858+
859+
860+
861+
862+
863+
854864

855865

856866

test/jdk/java/util/Formatter/BasicBigInteger.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -435,7 +435,7 @@ public static void test() {
435435
test("%-4c", "i ", 'i');
436436
test("%4C", " I", 'i');
437437
test("%-4C", "I ", 'i');
438-
test("%c", "i", new Character('i'));
438+
test("%c", "i", Character.valueOf('i'));
439439
test("%c", "H", (byte) 72);
440440
test("%c", "i", (short) 105);
441441
test("%c", "!", (int) 33);
@@ -493,7 +493,7 @@ public static void test() {
493493
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
494494
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
495495
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
496-
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
496+
tryCatch("%#s", FormatFlagsConversionMismatchException.class, (Object)null);
497497

498498
//---------------------------------------------------------------------
499499
// %h
@@ -766,6 +766,16 @@ public static void test() {
766766

767767

768768

769+
770+
771+
772+
773+
774+
775+
776+
777+
778+
769779

770780

771781

test/jdk/java/util/Formatter/BasicBoolean.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -435,7 +435,7 @@ public static void test() {
435435
test("%-4c", "i ", 'i');
436436
test("%4C", " I", 'i');
437437
test("%-4C", "I ", 'i');
438-
test("%c", "i", new Character('i'));
438+
test("%c", "i", Character.valueOf('i'));
439439
test("%c", "H", (byte) 72);
440440
test("%c", "i", (short) 105);
441441
test("%c", "!", (int) 33);
@@ -493,7 +493,7 @@ public static void test() {
493493
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
494494
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
495495
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
496-
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
496+
tryCatch("%#s", FormatFlagsConversionMismatchException.class, (Object)null);
497497

498498
//---------------------------------------------------------------------
499499
// %h
@@ -1650,6 +1650,16 @@ public static void test() {
16501650

16511651

16521652

1653+
1654+
1655+
1656+
1657+
1658+
1659+
1660+
1661+
1662+
16531663

16541664

16551665

test/jdk/java/util/Formatter/BasicBooleanObject.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -435,7 +435,7 @@ public static void test() {
435435
test("%-4c", "i ", 'i');
436436
test("%4C", " I", 'i');
437437
test("%-4C", "I ", 'i');
438-
test("%c", "i", new Character('i'));
438+
test("%c", "i", Character.valueOf('i'));
439439
test("%c", "H", (byte) 72);
440440
test("%c", "i", (short) 105);
441441
test("%c", "!", (int) 33);
@@ -493,7 +493,7 @@ public static void test() {
493493
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
494494
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
495495
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
496-
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
496+
tryCatch("%#s", FormatFlagsConversionMismatchException.class, (Object)null);
497497

498498
//---------------------------------------------------------------------
499499
// %h
@@ -1650,6 +1650,16 @@ public static void test() {
16501650

16511651

16521652

1653+
1654+
1655+
1656+
1657+
1658+
1659+
1660+
1661+
1662+
16531663

16541664

16551665

test/jdk/java/util/Formatter/BasicByte.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -435,7 +435,7 @@ public static void test() {
435435
test("%-4c", "i ", 'i');
436436
test("%4C", " I", 'i');
437437
test("%-4C", "I ", 'i');
438-
test("%c", "i", new Character('i'));
438+
test("%c", "i", Character.valueOf('i'));
439439
test("%c", "H", (byte) 72);
440440
test("%c", "i", (short) 105);
441441
test("%c", "!", (int) 33);
@@ -493,7 +493,7 @@ public static void test() {
493493
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
494494
tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
495495
tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
496-
tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
496+
tryCatch("%#s", FormatFlagsConversionMismatchException.class, (Object)null);
497497

498498
//---------------------------------------------------------------------
499499
// %h
@@ -522,12 +522,22 @@ public static void test() {
522522

523523

524524

525-
526525
byte minByte = Byte.MIN_VALUE; // -128
527526

528527

529528

530529

530+
531+
532+
533+
534+
535+
536+
537+
538+
539+
540+
531541
//---------------------------------------------------------------------
532542
// %d
533543
//

0 commit comments

Comments
 (0)