• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

My first experience with TDD - Revealed a "design" flaw early on or was I being dumb ?

 
Ranch Hand
Posts: 182
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made a really lame mistake in logic. Have you seen anything as lame as this ?

I was making a password validator class. Requirements were - check for min pass size, max pass size, min number of capital letters, min number of digits etc. I decided to have only a default, no args constructor. For the the min pass size and max pass size, I had setter methods. These setter methods had the following logic -



Also, you are not allowed to set the value below 1 for minSize or maxSize. After I finished adding the logic above, and ran the tests which I hoped would pass, Junit threw the error "cannot initialize" the password validator. Duh ! Makes sense now. The minSize = 1 and maxSize = 1 by default. So, if you set any of those variables with a value > 1 using the setters, an exception will always be thrown and you can never set them. I feel so stupid now. But, the consoling fact is that I did not write any more validation methods and then discover this huge elephant size bug. Maybe I should have a constructor or single setter method that takes minSize and maxSize and does the checking instead of having separate setters.

Was this my stupidity or just the benefits of TDD ?
reply
    Bookmark Topic Watch Topic
  • New Topic