void () { Presentation p = new Presentation(); Map<String, String> actualEvents = new HashMap<>(); p.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String oldValue = actualEvents.put(evt.getPropertyName(), evt.getOldValue() + "->" + evt.getNewValue()); assertNull("Repeating event: " + evt.getPropertyName(), oldValue); } }); Map<String, String> expectedEvents = Map.of("mnemonicKey", "0->73", "mnemonicIndex", "-1->1", "text", "null->Git", "textWithSuffix", "null->Git"); p.setTextWithMnemonic(() -> TextWithMnemonic.parse("G&it")); assertEquals(expectedEvents, actualEvents); actualEvents.clear(); p.setTextWithMnemonic(() -> TextWithMnemonic.parse("Git(&G)")); Map<String, String> expectedEvents2 = // "text" event is not sent, as text without suffix is not changed Map.of("mnemonicKey", "73->71", "mnemonicIndex", "1->4", "textWithSuffix", "Git->Git(G)"); assertEquals(expectedEvents2, actualEvents); }