Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for Painless general casting of boolean and Boolean #37780

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,158 @@ public void testStringCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("String o = 'string'; ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("String o = 'string'; ArrayList b = (ArrayList)o;"));
}

public void testPrimitiveBooleanCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Object n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Object n = (Object)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Number n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Number n = (boolean)o;"));

exec("boolean o = true; boolean b = o;");
exec("boolean o = true; boolean b = (boolean)o;");

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; byte b = (byte)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; short b = (short)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; char b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; char b = (char)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; int b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; int b = (int)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; long b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; long b = (long)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; float b = (float)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; double b = (double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Boolean b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Boolean b = (Boolean)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Byte b = (Byte)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Short b = (Short)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Character b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Character b = (Character)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Integer b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Integer b = (Integer)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Long b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Long b = (Long)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Float b = (Float)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("boolean o = true; ArrayList b = (ArrayList)o;"));
}

public void testBoxedBooleanCasts() {
exec("Boolean o = Boolean.valueOf(true); Object n = o;");
exec("Boolean o = null; Object n = o;");
exec("Boolean o = Boolean.valueOf(true); Object n = (Object)o;");
exec("Boolean o = null; Object n = (Object)o;");

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Number n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Number n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Number n = (Boolean)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Number n = (Boolean)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); boolean b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; boolean b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); boolean b = (boolean)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; boolean b = (boolean)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); byte b = (byte)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; byte b = (byte)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); short b = (short)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; short b = (short)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); char b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; char b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); char b = (char)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; char b = (char)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); int b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; int b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); int b = (int)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; int b = (int)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); long b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; long b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); long b = (long)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; long b = (long)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); float b = (float)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; float b = (float)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); double b = (double)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; double b = (double)o;"));

exec("Boolean o = Boolean.valueOf(true); Boolean b = o;");
exec("Boolean o = null; Boolean b = o;");
exec("Boolean o = Boolean.valueOf(true); Boolean b = (Boolean)o;");
exec("Boolean o = null; Boolean b = (Boolean)o;");

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Byte b = (Byte)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Byte b = (Byte)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Short b = (Short)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Short b = (Short)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Character b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Character b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Character b = (Character)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Character b = (Character)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Integer b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Integer b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Integer b = (Integer)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Integer b = (Integer)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Long b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Long b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Long b = (Long)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Long b = (Long)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Float b = (Float)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Float b = (Float)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); Double b = (Double)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = null; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Boolean o = Boolean.valueOf(true); ArrayList b = (ArrayList)o;"));
}
}