Using What I Learned at POODR to Refactor A Java Test Class
This fall, I attended Sandi Metzs' POODR workshop. Â I decided to sneak off during lunch (which is typically a no-no because work-life balance), and apply what I had learned at POODR to the building of my java server. Â But this early on there is no big refactor in the production code. Â I knew right away that the most obvious places of duplication would appear in my test code, so I decided to use what I learned there.Â
Here is what I did:
1. I've written the test code that meet all of the requirements for a particular story.  All of my tests are passing, and I have not refactored any code. Refactoring too early can lead to the wrong level of abstraction, something that I'd be concerned with in production code, not test code.  But this is still good practice.  As you can see, there is some unnecessary duplication. Â
https://gist.github.com/LNA/3f0f0557a4448a6edf41
2. I want to look for the things that are the most alike. Â There is 1 line of code that appears in every test:
RequestParser parser = new RequestParser();
And there is a second line of code that appears in 3/4 of the tests:
RequestParser parser = new RequestParser();
So we will first focus on refactoring the thing that appears the most.Â
3. Add before you take away: Add the new code and make sure that the tests still compile:
https://gist.github.com/LNA/d1e80bb2be9d7f22a423
4. After you prove that it compiles, pull out the kind of living, kind of dead code(zombie code?). Â Make sure that the newly refactored code passes.
https://gist.github.com/LNA/b69d0deb930894728cfc
5. Do it all again, with the next most similar thing.
https://gist.github.com/LNA/9e44b19ad1da081eb239



















