اختبار الحالة النهائية للعملية Java 44- Use an assert to test the validity of a hypothesis

في هذا الفيديو من جافا JAVA, سنتحدث عن كيفية اختبار صحة جميع الافتراضات التي تم إجراؤها في البرنامج, اي سنتحدث عن كيفية التحقق من الحالة النهائية للعملية بعد تشغيل البرنامج. Use an assert to test the validity of a hypothesis


package package3;

public class Apple{

  /*
   * assert expression
   * assert expression1 : expression2
   */

    public static void main(String... args) {
    String name="Apple1";
    if (name!="Apple") {
      System.out.println(name);
    }
    assert name=="Apple" : "invalid";
    System.out.println("after assert : "+name);

    }
}

-------------
javac Apple.java
java Apple.java

affiche :
         Apple1
         after assert : Apple1

-------------
java -ea Apple.java

affiche :
         Apple1
         Exception in thread "main" java.lang.AssertionError: invalid
         at package3.Apple.main(Apple.java:15)