Learning In Tests

I was testing a method that did some validation of a 2 character state. It’s legacy code, very few tests so I’m learning about how the code really works as I go along. I was writing a test for the following line:

else if (!BasicUtils.isState(state.trim()))

I wrote a test set the state property to “AA” and asserted that the validation failed. Problem was the validation passed and the test failed. OK, I found a weird defect. I took a bit of digging through layers until I got to the EJB layer where I found my answer:

stateValue.add("Armed Forces the Americas");
state.add("AA");

Turns out “AA” is a valid state code defined by the US Post Office.