Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Do you want to know what exactly went wrong? Commented Apr 19, 2016 at 12:30
  • 1
    Related: programmers.stackexchange.com/a/315979/120379 Commented Apr 19, 2016 at 12:34
  • 2
    As a rule I would not allow a customer object to be in an invalid state. Missing (or empty) email might be ok an illegal email not. If you allow your customer objects to be mutable, the validation should happen in the properties. That validation can of course be done in another class reusing the validation of emails in other classes. Commented Apr 19, 2016 at 12:43
  • 2
    How hard would it be to create Customer objects which have exactly one of the fields invalid and the others valid, so you test all three "implementation details" with only the one public method? (assuming it makes any sense to allow "invalid Customers" to be constructed in the first place) Commented Apr 19, 2016 at 12:50
  • 1
    An alternative perspective to take would be to say: if I pass in an instance with what I believe to be a single incorrect field and it fails the overall validation haven't I proven that the validation method works? It's none of my business which sub-validation method it's calling internally that returns false, as long as the Validation unit behaves as expected. Commented Apr 19, 2016 at 14:15