diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/creators/JvmErrorCreatorGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/creators/JvmErrorCreatorGen.java index 900eaf80d962..2eeee3859b51 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/creators/JvmErrorCreatorGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/creators/JvmErrorCreatorGen.java @@ -145,7 +145,7 @@ private void generateCreateErrorMethodSplits(ClassWriter cw, List arrayType = ((IntersectableReferenceType) array.getType()).getIntersectionType(); - assert arrayType.isPresent(); + Assert.assertTrue(arrayType.isPresent()); List constituentTypes = arrayType.get().getConstituentTypes(); int size = constituentTypes.size(); BArray arrayValue = @@ -396,12 +397,12 @@ public static Object validateFunctionParameterExtern(BFunctionPointer fpValue) { @Nullable private static BError validateFunctionType(FunctionType functionType) { Parameter[] parameters = functionType.getParameters(); - assert parameters[0].type.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG; + Assert.assertEquals(parameters[0].type.getTag(), TypeTags.TYPE_REFERENCED_TYPE_TAG); AnnotatableType annotatableType = (AnnotatableType) parameters[0].type; if (annotatableType.getAnnotation(intAnnotation) == null) { return constraintError; } - assert parameters[1].type.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG; + Assert.assertEquals(parameters[1].type.getTag(), TypeTags.TYPE_REFERENCED_TYPE_TAG); annotatableType = (AnnotatableType) parameters[1].type; if (annotatableType.getAnnotation(intAnnotation) == null) { return constraintError; @@ -500,10 +501,7 @@ public static BError getErrorValue(BString errorTypeName) { BString errorMsg = StringUtils.fromString("error message!"); BError bError = ErrorCreator.createError(errorModule, errorTypeName.getValue(), errorTypeName, ErrorCreator.createError(errorMsg), ValueCreator.createMapValue()); - // TODO: fix https://github.com/ballerina-platform/ballerina-lang/issues/41025 - String typeName = errorTypeName.getValue().equals("ResourceDispatchingError") ? - "RequestDispatchingError" : errorTypeName.getValue(); - assert bError.getType().getName().equals(typeName); + Assert.assertEquals(bError.getType().getName(), errorTypeName.getValue()); return bError; } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Accumulator.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Accumulator.java index 4da99ff82a35..a029b6a464c9 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Accumulator.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Accumulator.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.async.Callback; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.internal.values.ObjectValue; +import org.testng.Assert; /** * This class is used for Java interoperability tests. @@ -39,7 +40,7 @@ public class Accumulator { public static void accumulate(Environment env, ObjectValue intFunction, long from, long to) { Runtime runtime = env.getRuntime(); Future future = env.markAsync(); - assert from <= to; + Assert.assertTrue(from <= to); accumulateI(intFunction, from, to, runtime, future, new long[1]); } @@ -59,8 +60,8 @@ public void notifySuccess(Object result) { @Override public void notifyFailure(BError error) { - assert error == null; - assert false; + Assert.assertNull(error); + Assert.fail(); } }, null, PredefinedTypes.TYPE_NULL, i, true); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/AsyncInterop.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/AsyncInterop.java index 68a9d67cab04..13754a5f185c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/AsyncInterop.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/AsyncInterop.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; import io.ballerina.runtime.internal.scheduling.AsyncUtils; +import org.testng.Assert; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; @@ -59,7 +60,7 @@ private static void sleep() { try { Thread.sleep(1000); } catch (InterruptedException e) { - assert false; + Assert.fail(e.getMessage()); } } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java index e2a231cdaf0b..eabbe8a11feb 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java @@ -61,6 +61,7 @@ import io.ballerina.runtime.internal.values.TableValue; import io.ballerina.runtime.internal.values.TupleValueImpl; import io.ballerina.runtime.internal.values.TypedescValue; +import org.testng.Assert; import java.io.IOException; import java.math.BigDecimal; @@ -597,7 +598,7 @@ private static void sleep() { try { Thread.sleep(100); } catch (InterruptedException e) { - assert false; + Assert.fail(e.getMessage()); } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Timer.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Timer.java index 7918cb854c80..23396c56f264 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Timer.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/Timer.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.Runtime; import io.ballerina.runtime.internal.values.ObjectValue; +import org.testng.Assert; /** * This class is used for Java interoperability tests. @@ -47,7 +48,7 @@ public static void sleep(int millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { - assert false; + Assert.fail(e.getMessage()); } } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/VariableReturnType.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/VariableReturnType.java index ef1fe142fc41..e1a2a8686c51 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/VariableReturnType.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/VariableReturnType.java @@ -52,6 +52,7 @@ import io.ballerina.runtime.internal.values.ObjectValue; import io.ballerina.runtime.internal.values.TableValue; import io.ballerina.runtime.internal.values.TupleValueImpl; +import org.testng.Assert; import java.util.ArrayList; import java.util.List; @@ -152,7 +153,7 @@ public static MapValue query(BString query, BTypedesc typedesc) { public static BStream getStreamOfRecords(ObjectValue objectValue, BStream strm, BTypedesc typedesc) { RecordType streamConstraint = (RecordType) typedesc.getDescribingType(); - assert streamConstraint == TypeUtils.getImpliedType(strm.getConstraintType()); + Assert.assertSame(streamConstraint, TypeUtils.getImpliedType(strm.getConstraintType())); return strm; } @@ -242,7 +243,7 @@ public static BXml getXml(BTypedesc td, BXml val) { return val; } - assert describingType.getTag() == XML_COMMENT_TAG : describingType; + Assert.assertEquals(describingType.getTag(), XML_COMMENT_TAG, describingType.toString()); return val; } @@ -253,7 +254,7 @@ public static Object getInvalidValue(BTypedesc td1, BTypedesc td2) { return getRecord(td2); } - assert tag == RECORD_TYPE_TAG; + Assert.assertEquals(tag, RECORD_TYPE_TAG); return 200; } @@ -428,8 +429,8 @@ public static Object getResource(BObject client, BArray path, BTypedesc targetTy if (targetTypeTag == STRING_TAG) { return StringUtils.fromString(path.toString()); } - - assert targetTypeTag == INT_TAG; + + Assert.assertEquals(targetTypeTag, INT_TAG); return 0; } @@ -477,7 +478,7 @@ public static BArray funcWithMultipleArgs(long i, BTypedesc td, BArray arr) { return arr; } - assert td.getDescribingType().getTag() == INT_TAG; + Assert.assertEquals(td.getDescribingType().getTag(), INT_TAG); return ValueCreator.createArrayValue(new long[]{arr.getLength(), i}); } @@ -488,7 +489,7 @@ public static Object funcReturningUnionWithBuiltInRefType(Object strm, BTypedesc return strm; } - assert tag == BYTE_TAG; + Assert.assertEquals(tag, BYTE_TAG); if (strm == null) { return 100L; } @@ -501,22 +502,22 @@ public static Object getValueWithUnionReturnType(Object val, BTypedesc td) { Type describingType = td.getDescribingType(); if (tag == RECORD_TYPE_TAG) { - assert describingType.getTag() == INT_TAG; + Assert.assertEquals(describingType.getTag(), INT_TAG); return 101L; } if (tag == OBJECT_TYPE_TAG) { - assert describingType.getTag() == ARRAY_TAG && - ((BArrayType) describingType).getElementType().getTag() == STRING_TAG; + Assert.assertEquals(describingType.getTag(), ARRAY_TAG); + Assert.assertEquals(((BArrayType) describingType).getElementType().getTag(), STRING_TAG); return val; } - assert describingType.getTag() == BOOLEAN_TAG; + Assert.assertEquals(describingType.getTag(), BOOLEAN_TAG); return !((boolean) val); } public static BFunctionPointer getFunctionWithAnyFunctionParamType(BFunctionPointer x, BTypedesc td) { - assert td.getDescribingType().getTag() == INT_TAG; + Assert.assertEquals(td.getDescribingType().getTag(), INT_TAG); return x; } @@ -529,7 +530,7 @@ public static Object functionWithInferredArgForParamOfTypeReferenceType(BTypedes return 9876L; } - assert tag == STRING_TAG; + Assert.assertEquals(tag, STRING_TAG); return StringUtils.fromString("hello!"); } } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/values/modules/errors/errors.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/values/modules/errors/errors.bal index eddfd2c87c27..9ef879944eb0 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/values/modules/errors/errors.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/values/modules/errors/errors.bal @@ -34,6 +34,12 @@ public function validateAPI() { errorVar = getErrorValue("ResourceNotFoundError"); test:assertTrue(errorVar is ResourceNotFoundError); + + errorVar = getErrorValue("RequestDispatchingError"); + test:assertTrue(errorVar is RequestDispatchingError); + + errorVar = getErrorValue("StatusCodeError"); + test:assertTrue(errorVar is StatusCodeError); } function getErrorValue(string errorTypeName) returns error = @java:Method {