### Question:
NodeHandler { public void changeState(State newState) { State oldState = state; if (newState == State.DISCOVERED) { if (sourceNode != null && sourceNode.getPort() != node.getPort()) { changeState(State.DEAD); } else { sendPing(); } } if (!node.isDiscoveryNode()) { if (newState == State.ALIVE) { Node evictCandidate = nodeManager.getTable().addNode(this.node); if (evictCandidate == null) { newState = State.ACTIVE; } else { NodeHandler evictHandler = nodeManager.getNodeHandler(evictCandidate); if (evictHandler.state != State.EVICTCANDIDATE) { evictHandler.challengeWith(this); } } } if (newState == State.ACTIVE) { if (oldState == State.ALIVE) { nodeManager.getTable().addNode(node); } else if (oldState == State.EVICTCANDIDATE) { } else { } } if (newState == State.NONACTIVE) { if (oldState == State.EVICTCANDIDATE) { nodeManager.getTable().dropNode(node); replaceCandidate.changeState(State.ACTIVE); } else if (oldState == State.ALIVE) { } else { } } } if (newState == State.EVICTCANDIDATE) { sendPing(); } state = newState; } NodeHandler(Node node, NodeManager nodeManager); InetSocketAddress getInetSocketAddress(); Node getSourceNode(); void setSourceNode(Node sourceNode); Node getNode(); void setNode(Node node); State getState(); NodeStatistics getNodeStatistics(); void changeState(State newState); void handlePing(PingMessage msg); void handlePong(PongMessage msg); void handleNeighbours(NeighborsMessage msg); void handleFindNode(FindNodeMessage msg); void handleTimedOut(); void sendPing(); void sendPong(); void sendFindNode(byte[] target); void sendNeighbours(List<Node> neighbours, long sequence); @Override String toString();  }### Answer:
@Test public void stateNonActiveTest() throws Exception { Class clazz = NodeHandler.class; Constructor<NodeHandler> cn = clazz.getDeclaredConstructor(Node.class, NodeManager.class); NodeHandler nh = cn.newInstance(oldNode, nodeManager); Field declaredField = clazz.getDeclaredField("replaceCandidate"); declaredField.setAccessible(true); declaredField.set(nh, replaceHandler); nodeManager.getTable().addNode(oldNode); nh.changeState(NodeHandler.State.EVICTCANDIDATE); nh.changeState(NodeHandler.State.NONACTIVE); replaceHandler.changeState(NodeHandler.State.ALIVE); Assert.assertTrue(!nodeManager.getTable().contains(oldNode)); Assert.assertTrue(nodeManager.getTable().contains(replaceNode)); }