Skip to content

Commit 92c79a9

Browse files
zbynekniloc132
andauthored
Apply suggestions from code review
Co-authored-by: Colin Alworth <[email protected]>
1 parent 41c9c09 commit 92c79a9

File tree

1 file changed

+18
-1
lines changed
  • user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang

1 file changed

+18
-1
lines changed

user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/MathTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Tests for java.lang.String Java 12 API emulation.
2222
*/
23-
public class StringTest extends EmulTestBase {
23+
public class MathTest extends EmulTestBase {
2424

2525
public void testAbsExact() {
2626
assertEquals(Integer.MAX_VALUE, Math.absExact(hideFromCompiler(Integer.MAX_VALUE)));
@@ -43,4 +43,21 @@ public void testAbsExactWithFolding() {
4343
assertEquals(1, Math.absExact(-1L));
4444
assertThrowsArithmetic(() -> Math.absExact(Long.MIN_VALUE));
4545
}
46+
47+
private <T> T hideFromCompiler(T value) {
48+
if (Math.random() < -1) {
49+
// Can never happen, but fools the compiler enough not to optimize this call.
50+
fail();
51+
}
52+
return value;
53+
}
54+
55+
private void assertThrowsArithmetic(Runnable check) {
56+
try {
57+
check.run();
58+
fail("Should have failed");
59+
} catch (ArithmeticException ex) {
60+
// good
61+
}
62+
}
4663
}

0 commit comments

Comments
 (0)