I'd like to understand why the assertion on line 13 isn't appropriate.
The book's answer about which are true is that
neither line 5 and line 13 assertions is appropriate because ultimately they are testing the args of main().
But I think that test2 method could be used with another argument than the main's argument.
Could someone give me some help to understand it? Thanks!!!
From: JAVA OCP Java SE 6 Programmer Practice Exams - K&B
Chapter 3: Practice Exam I - exercise number 44
Assertions are in theory for testing code invariants, assumptions that must be true in order for the code to complete properly.
The example shown is testing for valid input, which isn't a typical usage for an assertion because it is, generally, user supplied.
Assertions aren't generally used in production code because there is an overhead and it is assumed that situations where the invariants fail
have been caught as coding errors during development and testing. LINE-5 and LINE-13 are trying to validate the input, that's why they are
in-appropriate usage ofassertion. Additionally, your assumption is correct that test2 can be used for some other way also, but currently the
author is talking about context of the example so in this example, the way assertion has been used is in-appropriate.