diff --git a/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeChecker.java b/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeChecker.java index e3fb73e402bd..5a4b1be11880 100644 --- a/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeChecker.java +++ b/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeChecker.java @@ -86,7 +86,7 @@ public static Object checkCast(Object sourceVal, BType targetType) { // if the source is a numeric value and the target type is a union, try to find a matching // member. if (sourceType.getTag() <= TypeTags.BOOLEAN_TAG && targetType.getTag() == TypeTags.UNION_TAG) { - for(BType memberType : ((BUnionType) targetType).getMemberTypes()) { + for (BType memberType : ((BUnionType) targetType).getMemberTypes()) { try { return TypeConverter.castValues(memberType, sourceVal); } catch (Exception e) { @@ -99,21 +99,22 @@ public static Object checkCast(Object sourceVal, BType targetType) { } public static long anyToInt(Object sourceVal) { - return TypeConverter.anyToInt(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, BTypes.typeInt)); + return TypeConverter.anyToIntCast(sourceVal, + () -> BallerinaErrors.createTypeCastError(sourceVal, BTypes.typeInt)); } public static double anyToFloat(Object sourceVal) { - return TypeConverter.anyToFloat(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, + return TypeConverter.anyToFloatCast(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, BTypes.typeFloat)); } public static boolean anyToBoolean(Object sourceVal) { - return TypeConverter.anyToBoolean(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, + return TypeConverter.anyToBooleanCast(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, BTypes.typeBoolean)); } public static int anyToByte(Object sourceVal) { - return TypeConverter.anyToByte(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, + return TypeConverter.anyToByteCast(sourceVal, () -> BallerinaErrors.createTypeCastError(sourceVal, BTypes.typeByte)); } @@ -1134,10 +1135,6 @@ private static boolean isEqual(Object lhsValue, Object rhsValue, List return false; } - if (lhsValue.equals(rhsValue)) { - return true; - } - int lhsValTypeTag = getType(lhsValue).getTag(); int rhsValTypeTag = getType(rhsValue).getTag(); diff --git a/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeConverter.java b/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeConverter.java index 3334574bb5da..a33683ded68f 100644 --- a/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeConverter.java +++ b/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/TypeConverter.java @@ -124,7 +124,7 @@ static long anyToInt(Object sourceVal, Supplier errorFunc) { throw errorFunc.get(); } - private static long anyToIntCast(Object sourceVal, Supplier errorFunc) { + static long anyToIntCast(Object sourceVal, Supplier errorFunc) { if (sourceVal instanceof Long) { return (Long) sourceVal; } else if (sourceVal instanceof Double) { @@ -162,7 +162,7 @@ static double anyToFloat(Object sourceVal, Supplier errorFunc) { throw errorFunc.get(); } - private static double anyToFloatCast(Object sourceVal, Supplier errorFunc) { + static double anyToFloatCast(Object sourceVal, Supplier errorFunc) { if (sourceVal instanceof Long) { return ((Long) sourceVal).doubleValue(); } else if (sourceVal instanceof Double) { @@ -269,7 +269,7 @@ static int anyToByte(Object sourceVal, Supplier errorFunc) { throw errorFunc.get(); } - private static int anyToByteCast(Object sourceVal, Supplier errorFunc) { + static int anyToByteCast(Object sourceVal, Supplier errorFunc) { if (sourceVal instanceof Long) { return intToByte((Long) sourceVal); } else if (sourceVal instanceof Double) { diff --git a/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/values/DecimalValue.java b/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/values/DecimalValue.java index 316971793e61..4014cb2ef36b 100644 --- a/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/values/DecimalValue.java +++ b/bvm/ballerina-runtime/src/main/java/org/ballerinalang/jvm/values/DecimalValue.java @@ -23,8 +23,6 @@ import org.ballerinalang.jvm.types.BType; import org.ballerinalang.jvm.types.BTypes; import org.ballerinalang.jvm.util.BLangConstants; -import org.ballerinalang.jvm.util.exceptions.BallerinaErrorReasons; -import org.ballerinalang.jvm.util.exceptions.BallerinaException; import java.math.BigDecimal; import java.math.BigInteger; diff --git a/compiler/ballerina-backend-jvm/src/main/ballerina/compiler_backend_jvm/jvm_cast_gen.bal b/compiler/ballerina-backend-jvm/src/main/ballerina/compiler_backend_jvm/jvm_cast_gen.bal index e2d51668947d..9abce5f81564 100644 --- a/compiler/ballerina-backend-jvm/src/main/ballerina/compiler_backend_jvm/jvm_cast_gen.bal +++ b/compiler/ballerina-backend-jvm/src/main/ballerina/compiler_backend_jvm/jvm_cast_gen.bal @@ -266,6 +266,7 @@ function generateCheckCastToFiniteType(jvm:MethodVisitor mv, bir:BType sourceTyp // ------------------------------------------------------------------ // Generate Cast Methods - Performs cast without type checking // ------------------------------------------------------------------ + function generateCast(jvm:MethodVisitor mv, bir:BType sourceType, bir:BType targetType) { if (targetType is bir:BTypeInt) { generateCastToInt(mv, sourceType); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index 342f7cd6b056..63f9aabb964c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -2941,9 +2941,7 @@ public void visit(BLangFunctionVarRef functionVarRef) { @Override public void visit(BLangStructFieldAccessExpr fieldAccessExpr) { - BType expType = fieldAccessExpr.type; - fieldAccessExpr.type = symTable.anyType; - result = addConversionExprIfRequired(fieldAccessExpr, expType); + result = fieldAccessExpr; } @Override diff --git a/tests/ballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/typecast/NumericConversionTest.java b/tests/ballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/typecast/NumericConversionTest.java index 9fc0ddc1ab0b..264d0dfcbc6d 100644 --- a/tests/ballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/typecast/NumericConversionTest.java +++ b/tests/ballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/typecast/NumericConversionTest.java @@ -188,7 +188,7 @@ public void testIntAsByte(String functionName, int i) { Assert.assertEquals(returns.length, 2); Assert.assertSame(returns[0].getClass(), BBoolean.class); Assert.assertTrue(((BBoolean) returns[0]).booleanValue(), "expected bytes to be the same"); - Assert.assertEquals(((ValueType) returns[1]).byteValue(), (new BInteger(i)).byteValue(), "incorrect int " + + Assert.assertEquals(((BValueType) returns[1]).byteValue(), (new BInteger(i)).byteValue(), "incorrect int " + "representation as byte"); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/BinaryExprEvalPrecedenceTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/BinaryExprEvalPrecedenceTest.java index acd7359aeeba..f40820dc2fb6 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/BinaryExprEvalPrecedenceTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/BinaryExprEvalPrecedenceTest.java @@ -22,7 +22,6 @@ import org.ballerinalang.test.util.BCompileUtil; import org.ballerinalang.test.util.BRunUtil; import org.ballerinalang.test.util.CompileResult; -import org.ballerinalang.util.exceptions.BLangRuntimeException; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -56,16 +55,15 @@ public void testBinaryOrExprWithLeftMostExprTrue() { Assert.assertEquals(actualResult, expectedResult); } - //TODO this expected NullPointerException should be properly handled at ballerina layer when - //TODO accessing non existing JSON elements. - @Test(description = "Test binary OR expression with " + - "left most expr evaluated to false expression.", expectedExceptions = {BLangRuntimeException.class}) + @Test(description = "Test binary OR expression with left most expr evaluated to false expression.") public void testBinaryOrExprWithLeftMostExprFalseNegativeCase() { boolean one = false; boolean two = false; boolean three = false; BValue[] args = {new BBoolean(one), new BBoolean(two), new BBoolean(three)}; - BRunUtil.invoke(result, "binaryOrExprWithLeftMostSubExprTrue", args); + BValue[] returns = BRunUtil.invoke(result, "binaryOrExprWithLeftMostSubExprTrue", args); + boolean actualResult = ((BBoolean) returns[0]).booleanValue(); + Assert.assertEquals(actualResult, one); } @Test(description = "Test binary AND expression with left most expr evaluated to false expression.") @@ -85,16 +83,15 @@ public void testBinaryAndExprWithLeftMostExprTrue() { Assert.assertEquals(actualResult, expectedResult); } - //TODO this expected NullPointerException should be properly handled at ballerina layer when - //TODO accessing non existing JSON elements. - @Test(description = "Test binary AND expression with " + - "left most expr evaluated to true expression.", expectedExceptions = {BLangRuntimeException.class}) + @Test(description = "Test binary AND expression with left most expr evaluated to true expression.") public void testBinaryAndExprWithLeftMostExprFalseNegativeCase() { boolean one = true; boolean two = false; boolean three = false; BValue[] args = {new BBoolean(one), new BBoolean(two), new BBoolean(three)}; - BRunUtil.invoke(result, "binaryANDExprWithLeftMostSubExprFalse", args); + BValue[] returns = BRunUtil.invoke(result, "binaryANDExprWithLeftMostSubExprFalse", args); + boolean actualResult = ((BBoolean) returns[0]).booleanValue(); + Assert.assertEquals(actualResult, false); } @Test(description = "Test multi binary expression with OR sub expressions inside If condition.") diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionNegativeTest.java index 93057cdf6bd9..6967de957182 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionNegativeTest.java @@ -60,7 +60,7 @@ public void testIncompatibleJsonToStructWithErrors() { // check the error Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: 'json' value cannot be converted as 'Person'"); + Assert.assertEquals(errorMsg, "'json' value cannot be converted to 'Person'"); } @Test @@ -68,7 +68,7 @@ public void testEmptyJSONtoStructWithoutDefaults() { BValue[] returns = BRunUtil.invoke(negativeResult, "testEmptyJSONtoStructWithoutDefaults"); Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: 'json' value cannot be converted as " + Assert.assertEquals(errorMsg, "'json' value cannot be converted to " + "'StructWithoutDefaults'"); } @@ -77,7 +77,7 @@ public void testEmptyMaptoStructWithDefaults() { BValue[] returns = BRunUtil.invoke(negativeResult, "testEmptyMaptoStructWithDefaults"); Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: 'map' value cannot be converted as " + Assert.assertEquals(errorMsg, "'map' value cannot be converted to " + "'StructWithDefaults'"); } @@ -86,7 +86,7 @@ public void testEmptyMaptoStructWithoutDefaults() { BValue[] returns = BRunUtil.invoke(negativeResult, "testEmptyMaptoStructWithoutDefaults"); Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: 'map' value cannot be converted as " + Assert.assertEquals(errorMsg, "'map' value cannot be converted to " + "'StructWithoutDefaults'"); } @@ -94,7 +94,7 @@ public void testEmptyMaptoStructWithoutDefaults() { public void testTupleConversionFail() { BValue[] returns = BRunUtil.invoke(negativeResult, "testTupleConversionFail"); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: '(T1,T1)' value cannot be converted as '(T1," + Assert.assertEquals(errorMsg, "'(T1,T1)' value cannot be converted to '(T1," + "T2)'"); } @@ -103,7 +103,7 @@ public void testArrayToJsonFail() { BValue[] returns = BRunUtil.invoke(negativeResult, "testArrayToJsonFail"); Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: 'TX[]' value cannot be converted as 'json'"); + Assert.assertEquals(errorMsg, "'TX[]' value cannot be converted to 'json'"); } @Test(description = "Test passing tainted value with convert") @@ -140,7 +140,7 @@ public void testIncompatibleImplicitConversion() { BValue[] returns = BRunUtil.invoke(negativeResult, "testIncompatibleImplicitConversion"); Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, "incompatible convert operation: 'string' value 'abjd' cannot be converted as " + Assert.assertEquals(errorMsg, "'string' value 'abjd' cannot be converted to " + "'int'"); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionTest.java index 0ee3f112b227..bc688762ed9f 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/conversion/NativeConversionTest.java @@ -232,8 +232,7 @@ public void testMapToJsonConversion() { @Test(description = "Test converting a struct with map of blob to a JSON", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'Info2' value cannot be converted as" - + " 'json'.*") + expectedExceptionsMessageRegExp = ".*'Info2' value cannot be converted to 'json'.*") public void testStructWithIncompatibleTypeToJson() { BRunUtil.invoke(compileResult, "testStructWithIncompatibleTypeToJson"); } @@ -263,22 +262,21 @@ public void testMapWithMissingOptionalFieldsToStruct() { @Test(description = "Test converting a map with incompatible inner array to a struct", expectedExceptions = { BLangRuntimeException.class }, expectedExceptionsMessageRegExp = - ".*incompatible convert operation: 'map' value cannot be converted as 'Person'.*") + ".*'map' value cannot be converted to 'Person'.*") public void testMapWithIncompatibleArrayToStruct() { BRunUtil.invoke(compileResult, "testMapWithIncompatibleArrayToStruct"); } @Test(description = "Test converting a map with incompatible inner struct to a struct", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'map' value cannot be converted " - + "as 'Employee'.*") + expectedExceptionsMessageRegExp = ".*'map' value cannot be converted to 'Employee'.*") public void testMapWithIncompatibleStructToStruct() { BRunUtil.invoke(compileResult, "testMapWithIncompatibleStructToStruct"); } @Test(description = "Test converting a incompatible JSON to a struct", expectedExceptions = {BLangRuntimeException.class}, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json' value cannot be converted as " + expectedExceptionsMessageRegExp = ".*'json' value cannot be converted to " + "'Person'.*") public void testIncompatibleJsonToStruct() { BRunUtil.invoke(compileResult, "testIncompatibleJsonToStruct"); @@ -295,48 +293,45 @@ public void testJsonToStructWithMissingOptionalFields() { @Test(description = "Test converting a incompatible JSON to a struct", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"incompatible " - + "convert operation: 'json' value cannot be converted as 'Person'\"\\}.*") + expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"'json' value " + + "cannot be converted to 'Person'\"\\}.*") public void testJsonToStructWithMissingRequiredFields() { BRunUtil.invoke(compileResult, "testJsonToStructWithMissingRequiredFields"); } @Test(description = "Test converting a JSON with incompatible inner map to a struct", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"incompatible " - + "convert operation: 'json' value cannot be converted as 'Person'\"\\}.*") + expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"'json' value " + + "cannot be converted to 'Person'\"\\}.*") public void testJsonWithIncompatibleMapToStruct() { BRunUtil.invoke(compileResult, "testJsonWithIncompatibleMapToStruct"); } @Test(description = "Test converting a JSON with incompatible inner struct to a struct", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"incompatible " - + "convert operation: 'json' value cannot be converted as 'Person'\"\\}.*") + expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"'json' value " + + "cannot be converted to 'Person'\"\\}.*") public void testJsonWithIncompatibleStructToStruct() { BRunUtil.invoke(compileResult, "testJsonWithIncompatibleStructToStruct"); } @Test(description = "Test converting a JSON array to a struct", expectedExceptions = {BLangRuntimeException.class}, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json\\[\\]' value cannot be converted" - + " as 'Person'.*") + expectedExceptionsMessageRegExp = ".*'json\\[\\]' value cannot be converted to 'Person'.*") public void testJsonArrayToStruct() { BRunUtil.invoke(compileResult, "testJsonArrayToStruct"); } @Test(description = "Test converting a JSON with incompatible inner type to a struct", expectedExceptions = {BLangRuntimeException.class}, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json' value cannot be converted as " - + "'Person'.*") + expectedExceptionsMessageRegExp = ".*'json' value cannot be converted to 'Person'.*") public void testJsonWithIncompatibleTypeToStruct() { BRunUtil.invoke(compileResult, "testJsonWithIncompatibleTypeToStruct"); } @Test(description = "Test converting a struct with map of blob to a JSON", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'Info' value cannot be converted as " - + "'json'.*") + expectedExceptionsMessageRegExp = ".*'Info' value cannot be converted to 'json'.*") public void testStructWithIncompatibleTypeMapToJson() { BRunUtil.invoke(compileResult, "testStructWithIncompatibleTypeMapToJson"); } @@ -399,7 +394,7 @@ public void testJsonIntArrayToStringArray() { @Test(description = "Test converting a JSON array to xml array", expectedExceptions = {BLangRuntimeException.class}, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json' value cannot be converted as " + expectedExceptionsMessageRegExp = ".*'json' value cannot be converted to " + "'XmlArray.*") public void testJsonToXmlArray() { BRunUtil.invoke(compileResult, "testJsonToXmlArray"); @@ -416,15 +411,15 @@ public void testNullJsonToArray() { @Test(description = "Test converting a JSON null to string array", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"incompatible " - + "convert operation: 'json' value cannot be converted as 'StringArray'\"\\}.*") + expectedExceptionsMessageRegExp = "error: \\{ballerina\\}ConversionError \\{\"message\":\"'json' value " + + "cannot be converted to 'StringArray'\"\\}.*") public void testNullJsonArrayToArray() { BRunUtil.invoke(compileResult, "testNullJsonArrayToArray"); } @Test(description = "Test converting a JSON string to string array", expectedExceptions = {BLangRuntimeException.class}, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json' value cannot be converted as " + expectedExceptionsMessageRegExp = ".*'json' value cannot be converted to " + "'StringArray.*") public void testNonArrayJsonToArray() { BRunUtil.invoke(compileResult, "testNonArrayJsonToArray"); @@ -583,7 +578,7 @@ public void testJsonToMapConstrained2() { @Test(description = "Test converting json to constrained map", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json' value cannot be converted as " + expectedExceptionsMessageRegExp = ".*'json' value cannot be converted to " + "'map'.*") public void testJsonToMapConstrainedFail() { BRunUtil.invoke(compileResult, "testJsonToMapConstrainedFail"); @@ -655,7 +650,7 @@ public void testJsonToArray2() { @Test(description = "Test an invalid json to array conversion", expectedExceptions = { BLangRuntimeException.class }, - expectedExceptionsMessageRegExp = ".*incompatible convert operation: 'json' value cannot be converted as " + expectedExceptionsMessageRegExp = ".*'json' value cannot be converted to " + "'int\\[\\]'.*") public void testJsonToArrayFail() { BRunUtil.invoke(compileResult, "testJsonToArrayFail"); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/fieldaccess/SafeNavigationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/fieldaccess/SafeNavigationTest.java index b4babb59ffe8..4283ce16dda1 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/fieldaccess/SafeNavigationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/fieldaccess/SafeNavigationTest.java @@ -231,9 +231,9 @@ public void testJSONNilLiftingOnLHS_1() { Assert.assertEquals(returns[3].stringValue(), "{\"info\":{\"address4\":{\"city\":\"Jaffna\"}}}"); } - @Test(expectedExceptions = {BLangRuntimeException.class}, - expectedExceptionsMessageRegExp = "error: failed to get element from json: " + - "\\{\"message\":\"array index out of range: index: 2, size: 0\"\\}.*") + @Test(expectedExceptions = { BLangRuntimeException.class }, + expectedExceptionsMessageRegExp = "error: failed to get element from json: array index out of range:" + + " index: 2, size: 0.*") public void testJSONNilLiftingOnLHS_2() { BRunUtil.invoke(result, "testJSONNilLiftingOnLHS_2"); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/foreach/ForeachJSONTests.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/foreach/ForeachJSONTests.java index f3a499069549..8e7c3ba1b03d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/foreach/ForeachJSONTests.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/foreach/ForeachJSONTests.java @@ -65,8 +65,8 @@ public void testArrayOfJSON() { @Test public void testJSONString() { - String result = "{ballerina}ConversionError {\"message\":\"incompatible convert operation: 'string' value " - + "cannot be converted as 'map'\"}"; + String result = "{ballerina}ConversionError {\"message\":\"'string' value " + + "cannot be converted to 'map'\"}"; BValue[] returns = BRunUtil.invoke(program, "testJSONString"); Assert.assertEquals(returns.length, 1); Assert.assertEquals(returns[0].stringValue(), result); @@ -74,8 +74,8 @@ public void testJSONString() { @Test public void testJSONNumber() { - String result = "{ballerina}ConversionError {\"message\":\"incompatible convert operation: 'int' value cannot" - + " be converted as 'map'\"}"; + String result = "{ballerina}ConversionError {\"message\":\"'int' value cannot" + + " be converted to 'map'\"}"; BValue[] returns = BRunUtil.invoke(program, "testJSONNumber"); Assert.assertEquals(returns.length, 1); Assert.assertEquals(returns[0].stringValue(), result); @@ -83,8 +83,8 @@ public void testJSONNumber() { @Test public void testJSONBoolean() { - String result = "{ballerina}ConversionError {\"message\":\"incompatible convert operation: 'boolean' value " - + "cannot be converted as 'map'\"}"; + String result = "{ballerina}ConversionError {\"message\":\"'boolean' value " + + "cannot be converted to 'map'\"}"; BValue[] returns = BRunUtil.invoke(program, "testJSONBoolean"); Assert.assertEquals(returns.length, 1); Assert.assertEquals(returns[0].stringValue(), result); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java index 9991459e3e80..baf1cb328259 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java @@ -95,7 +95,7 @@ public void byteValueRuntimeNegative1() { Assert.assertEquals(returnValue.length, 1); Assert.assertTrue(returnValue[0] instanceof BError); Assert.assertEquals(returnValue[0].stringValue(), "{ballerina}NumberConversionError {\"message\":" + - "\"incompatible convert operation: 'int' value '-12' cannot be converted as 'byte'\"}"); + "\"'int' value '-12' cannot be converted to 'byte'\"}"); } @Test(description = "Test int to byte conversion negative") @@ -104,7 +104,7 @@ public void byteValueRuntimeNegative2() { Assert.assertEquals(returnValue.length, 1); Assert.assertTrue(returnValue[0] instanceof BError); Assert.assertEquals(returnValue[0].stringValue(), "{ballerina}NumberConversionError {\"message\":" + - "\"incompatible convert operation: 'int' value '-257' cannot be converted as 'byte'\"}"); + "\"'int' value '-257' cannot be converted to 'byte'\"}"); } @Test(description = "Test int to byte conversion negative") @@ -113,6 +113,6 @@ public void byteValueRuntimeNegative3() { Assert.assertEquals(returnValue.length, 1); Assert.assertTrue(returnValue[0] instanceof BError); Assert.assertEquals(returnValue[0].stringValue(), "{ballerina}NumberConversionError {\"message\":" + - "\"incompatible convert operation: 'int' value '12,345' cannot be converted as 'byte'\"}"); + "\"'int' value '12,345' cannot be converted to 'byte'\"}"); } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/ConstrainedMapTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/ConstrainedMapTest.java index 59f7dd0c09b2..d04acb724f6a 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/ConstrainedMapTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/ConstrainedMapTest.java @@ -431,8 +431,7 @@ public void testJsonToStructConversionStructWithConstrainedMapNegative() { "testJsonToStructConversionStructWithConstrainedMapNegative"); Assert.assertTrue(returns[0] instanceof BError); String errorMsg = ((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(); - Assert.assertEquals(errorMsg, - "incompatible convert operation: 'json' value cannot be converted as 'PersonComplexTwo'"); + Assert.assertEquals(errorMsg, "'json' value cannot be converted to 'PersonComplexTwo'"); } @Test(description = "Test constrained map with union retrieving string value.") diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java index 6690ea74e438..b0d2b5e3dd85 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java @@ -207,7 +207,7 @@ public void testIncompatibleJsonToStructWithErrors() { Assert.assertSame(returns[0].getClass(), BError.class); Assert.assertEquals(((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(), - "incompatible convert operation: 'json' value cannot be converted as 'Person'"); + "'json' value cannot be converted to 'Person'"); } @Test(description = "Test incompatible json to struct with errors.") @@ -219,7 +219,7 @@ public void testJsonToStructWithErrors() { Assert.assertSame(returns[0].getClass(), BError.class); Assert.assertEquals(((BMap) ((BError) returns[0]).getDetails()).get("message").stringValue(), - "incompatible convert operation: 'json' value cannot be converted as 'PersonA'"); + "'json' value cannot be converted to 'PersonA'"); } @Test(description = "Test compatible struct with force casting.")