Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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 ?
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic