diff --git a/src/main/java/devoxx/NullPointerDereference.java b/src/main/java/devoxx/NullPointerDereference.java index af0fe34..c60ec38 100644 --- a/src/main/java/devoxx/NullPointerDereference.java +++ b/src/main/java/devoxx/NullPointerDereference.java @@ -2,15 +2,16 @@ public class NullPointerDereference { - public int getNumberOfPawsPlusOne(String animal) { + public int getNumberOfPawsPlusOne(String animal, String fred) { String trimmedAnimal = trim(animal); + String trimmedFred = trim(fred); int paws; if ("dog".equals(trimmedAnimal)) { paws = 4; } else if (trimmedAnimal.equals("tom")) { // NullPointer issue raised paws = 5; - } else if (trimmedAnimal.equals("Martin")) { // NullPointer issue raised + } else if (trimmedFred.equals("Martin")) { // NullPointer issue raised paws = 3; } else if ("Centipede".equals(trimmedAnimal)) { paws = 100; diff --git a/src/test/java/devoxx/NullPointerDereferenceTest.java b/src/test/java/devoxx/NullPointerDereferenceTest.java index ff83213..7e9851b 100644 --- a/src/test/java/devoxx/NullPointerDereferenceTest.java +++ b/src/test/java/devoxx/NullPointerDereferenceTest.java @@ -10,11 +10,11 @@ public class NullPointerDereferenceTest { @Test public void shouldGetDogPaws() { - assertEquals(underTest.getNumberOfPawsPlusOne("dog"), 4); + assertEquals(underTest.getNumberOfPawsPlusOne("dog", "basset"), 4); } @Test(expected = NullPointerException.class) public void ignoredTestThatWouldCoverBug() { - underTest.getNumberOfPawsPlusOne(""); + underTest.getNumberOfPawsPlusOne("", ""); } }