• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

assertion

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i tried to run assert false:false;
its saying
Exception in thread �main� java.lang.AssertionError: true
at Test.main(Test.java:3)

i thought that in simple assert statement the first expression should be a boolean, but here its seems that it should be true, and if our assumption is false then assertionError occurs.

is am right please someone explain.

-rahul
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi rahul ,

The second expression is the value which is added to the stack trace when assertion fails . so you would get only "false" as your assertion will always false.I'm wondering how you got "true" as in

Exception in thread �main� java.lang.AssertionError: true
at Test.main(Test.java:3)



Correct me if I said something wrong

greetings
Parthiban
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahul R khanna:
...if our assumption is false then assertionError occurs...


That part is correct. You are asserting (assuming) that a boolean condition is true. If it turns out to be false at runtime, then an assertion error is thrown.

However, Parthiban is also correct in pointing out that the second expression is passed to the error message, so if you use assert false : false; then we would expect the first "false" to cause the error to be thrown, and the second "false" to appear in the error message. So I don't see how "true" is showing in the error message.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic