Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assert syntax

 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep getting AssertionError on this statement, is there a way to do this?



Pardon my ignorance, as this is my first foray into assertions.

Any help appreciated!

Thanks
bw

 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Asserts can be disabled so you should do the assert like this:



I am not an assert expert so try it and let me know
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using the -enableassertion or -ea command line options when running your code?

John.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, the AssertionError is getting thrown because your getFName() is returning an empty String.
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your replies. I got it figured out. The assert statement was fine. I had something up stream that was cause my assert to be triggered.. So HA, score one for the debugging merits of assert!!

Thanks again to all that replied!
bw
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly what asserts are for, glad it worked

While I'm here B... you should probably change your name before a mod gets to you. Your user name must be a full name, unless your first name is really the letter B!
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, initials are allowed as the first name. It's the last name that can't be an initial.
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect your problem is caused by using == or != for object equality; you ought to use the equals() method.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you really want to get techinical you are missing a ')' on the if statement

Thanks Rob for clearing that up
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic