### Question:
PetriNetController implements Serializable { public void updateToken(String currentTokenName, String name, Color color) throws PetriNetComponentNotFoundException { Token token = petriNet.getComponent(currentTokenName, Token.class); if (!token.getId().equals(name)) { token.setId(name); } if (!token.getColor().equals(color)) { token.setColor(color); } } PetriNetController(PetriNet model, UndoableEditListener undoListener, GUIAnimator animator,
                              CopyPasteManager copyPasteManager, ZoomController zoomController,
                              PetriNetTab petriNetTab); PetriNetTab getPetriNetTab(); String getUniquePlaceName(); String getUniqueTransitionName(); boolean isSelected(PetriNetComponent component); void deselect(PetriNetComponent component); void deselectAll(); void translateSelected(Point translation); void select(Rectangle selectionRectangle); void select(PetriNetComponent component); List<UndoableEdit> deleteSelection(); UndoableEdit delete(PetriNetComponent component); void createNewToken(String name, Color color); Collection<Token> getNetTokens(); void updateToken(String currentTokenName, String name, Color color); PetriNet getPetriNet(); ArcController<S, T> getArcController(Arc<S, T> arc); PlaceController getPlaceController(Place place); AnnotationController getAnnotationController(Annotation annotation); TransitionController getTransitionController(final Transition transition); RateParameterController getRateParameterController(final String rateParameter); void selectToken(String tokenName); Token getToken(String name); void copySelection(); boolean isCopyInProgress(); void cancelPaste(); String getSelectedToken(); GUIAnimator getAnimator(); ZoomController getZoomController(); void paste(); DragManager getDragManager(); Collection<RateParameter> getRateParameters(); boolean isUniqueName(String id); boolean hasChanged(); void save(); FunctionalResults<Double> parseFunctionalExpression(String expr); UndoManager getUndoManager(); Set<PetriNetComponent> getSelectedComponents(); UndoableEditListener getUndoListener(); boolean toggleAnimation(); boolean isInAnimationMode(); SelectionManager getSelectionManager();  }### Answer:
@Test public void updateNameIfChanged() throws PetriNetComponentNotFoundException { Token token = mock(Token.class); String id = "id"; when(token.getId()).thenReturn(id); boolean enabled = true; Color color = Color.RED; when(token.getColor()).thenReturn(color); net.addToken(token); controller.updateToken(id, "new", color); verify(token).setId("new"); }
@Test public void doesNotUpdateNameIfNotChanged() throws PetriNetComponentNotFoundException { Token token = mock(Token.class); String id = "id"; when(token.getId()).thenReturn(id); boolean enabled = true; Color color = new Color(255, 0, 0); when(token.getColor()).thenReturn(color); net.addToken(token); controller.updateToken(id, id, color); verify(token, never()).setId(anyString()); }
@Test public void updateTokenColorIfChanged() throws PetriNetComponentNotFoundException { Token token = mock(Token.class); String id = "id"; when(token.getId()).thenReturn(id); boolean enabled = true; Color color = new Color(255, 0, 0); when(token.getColor()).thenReturn(color); net.addToken(token); Color newColor = new Color(0, 0, 0); controller.updateToken(id, id, newColor); verify(token).setColor(newColor); }
@Test public void doesNotUpdateTokenColorIfNotChanged() throws PetriNetComponentNotFoundException { Token token = mock(Token.class); String id = "id"; when(token.getId()).thenReturn(id); boolean enabled = true; Color color = new Color(255, 0, 0); when(token.getColor()).thenReturn(color); net.addToken(token); controller.updateToken(id, id, color); verify(token, never()).setColor(any(Color.class)); }