Skip to content

Commit

Permalink
Add Painless cast tests for long and Long (#40007)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdconrad authored Mar 15, 2019
1 parent c3fe51c commit c079729
Showing 1 changed file with 173 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ public void testPrimitiveByteCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("byte o = 0; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("byte o = 0; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("byte o = Byte.valueOf((byte)0); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("byte o = Byte.valueOf((byte)0); ArrayList b = (ArrayList)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("byte o = 0; ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("byte o = 0; ArrayList b = (ArrayList)o;"));
}

public void testByteCasts() {
Expand Down Expand Up @@ -1017,8 +1017,8 @@ public void testPrimitiveShortCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("short o = 0; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("short o = 0; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("short o = Byte.valueOf((short)0); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("short o = Byte.valueOf((short)0); ArrayList b = (ArrayList)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("short o = 0; ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("short o = 0; ArrayList b = (ArrayList)o;"));
}

public void testShortCasts() {
Expand All @@ -1034,7 +1034,7 @@ public void testShortCasts() {

expectScriptThrows(ClassCastException.class, () -> exec("Short o = Short.valueOf((short)0); String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Short o = null; String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Short o = Short.valueOf((byte)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Short o = Short.valueOf((short)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Short o = null; String n = (String)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Short o = Short.valueOf((short)0); boolean b = o;"));
Expand Down Expand Up @@ -1179,8 +1179,8 @@ public void testPrimitiveCharCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("char o = 0; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("char o = 0; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("char o = Byte.valueOf((short)0); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("char o = Byte.valueOf((short)0); ArrayList b = (ArrayList)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("char o = 0; ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("char o = 0; ArrayList b = (ArrayList)o;"));
}

public void testCharacterCasts() {
Expand All @@ -1196,7 +1196,7 @@ public void testCharacterCasts() {

expectScriptThrows(ClassCastException.class, () -> exec("Character o = Character.valueOf((char)0); String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Character o = null; String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Character o = Short.valueOf((byte)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Character o = Character.valueOf((char)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Character o = null; String n = (String)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Character o = Character.valueOf((char)0); boolean b = o;"));
Expand Down Expand Up @@ -1341,8 +1341,8 @@ public void testPrimitiveIntCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("int o = 0; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("int o = 0; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("int o = Byte.valueOf((short)0); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("int o = Byte.valueOf((short)0); ArrayList b = (ArrayList)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("int o = 0; ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("int o = 0; ArrayList b = (ArrayList)o;"));
}

public void testIntegerCasts() {
Expand All @@ -1358,7 +1358,7 @@ public void testIntegerCasts() {

expectScriptThrows(ClassCastException.class, () -> exec("Integer o = Integer.valueOf((int)0); String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Integer o = null; String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Integer o = Short.valueOf((byte)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Integer o = Integer.valueOf((int)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Integer o = null; String n = (String)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Integer o = Integer.valueOf((int)0); boolean b = o;"));
Expand Down Expand Up @@ -1444,4 +1444,166 @@ public void testIntegerCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("Integer o = Integer.valueOf((int)0); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Integer o = Integer.valueOf((int)0); ArrayList b = (ArrayList)o;"));
}

public void testPrimitiveLongCasts() {
expectScriptThrows(ClassCastException.class, () -> exec("long o = 0; Object n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("long o = 0; Object n = (Object)o;"));

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

expectScriptThrows(ClassCastException.class, () -> exec("long o = 0; String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("long o = 0; String n = (String)o;"));

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

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

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

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

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

exec("long o = 0; long b = o;");
exec("long o = 0; long b = (long)o;");

exec("long o = 0; float b = o;");
exec("long o = 0; float b = (float)o;");

exec("long o = 0; double b = o;");
exec("long o = 0; double b = (double)o;");

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

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

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

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

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

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

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

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

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

public void testLongCasts() {
exec("Long o = Long.valueOf((long)0); Object n = o;");
exec("Long o = null; Object n = o;");
exec("Long o = Long.valueOf((long)0); Object n = (Object)o;");
exec("Long o = null; Object n = (Object)o;");

exec("Long o = Long.valueOf((long)0); Number n = o;");
exec("Long o = null; Number n = o;");
exec("Long o = Long.valueOf((long)0); Number n = (Number)o;");
exec("Long o = null; Number n = (Number)o;");

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; String n = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); String n = (String)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; String n = (String)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); boolean b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; boolean b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); boolean b = (boolean)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; boolean b = (boolean)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); byte b = (byte)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; byte b = (byte)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); short b = (short)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; short b = (short)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); char b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; char b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); char b = (char)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; char b = (char)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); int b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; int b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); int b = (int)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; int b = (int)o;"));

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

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); float b = (float)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; float b = (float)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); double b = (double)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; double b = (double)o;"));

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

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Byte b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Byte b = (Byte)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Byte b = (Byte)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Short b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Short b = (Short)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Short b = (Short)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Character b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Character b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Character b = (Character)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Character b = (Character)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Integer b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Integer b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Integer b = (Integer)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Integer b = (Integer)o;"));

exec("Long o = Long.valueOf((long)0); Long b = o;");
exec("Long o = null; Long b = o;");
exec("Long o = Long.valueOf((long)0); Long b = (Long)o;");
exec("Long o = null; Long b = (Long)o;");

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Float b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Float b = (Float)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Float b = (Float)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Double b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); Double b = (Double)o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = null; Double b = (Double)o;"));

expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); ArrayList b = o;"));
expectScriptThrows(ClassCastException.class, () -> exec("Long o = Long.valueOf((long)0); ArrayList b = (ArrayList)o;"));
}
}

0 comments on commit c079729

Please sign in to comment.