So I'm brushing up on my data structures and have been working on Linked Lists and Hashtables. The following method is from my Linked List class:
public void add(String key, Model pair){ if(key.equals(null)|| pair.equals(null)){ System.out.println("Nothing was added"); //return; } else{ Node currentNode = new Node(key, pair); if(isEmpty()){ first = last = currentNode; first.setNextNode(currentNode); System.out.println(currentNode.toString() + " was added to " + "position " + size+1); } else{ last.setNextNode(currentNode); last = currentNode; System.out.println(currentNode.toString() + " was added to " + "position " + size+1); } size++; } }
In the first part I want nothing to be added if either the key or pair object are null. However, in my test case I get an NullPointerException.
@Test public void testAdd2(){ setUp(); list.add("Name", null); assertEquals(null, list.get("Name")); //assertEquals(0, list.printSize()); list.put(null, pair); assertEquals(null, list.get("name")); //assertEquals(0, list.printSize()); tearDown(); }
Any idea what is causing the error. I'm fairly new to JUnit also.
Thanks