### Question:
Redirect implements ActionListener, UIAware { public void actionPerformed (ActionEvent ev) { StringTokenizer st = new StringTokenizer (ev.getActionCommand ()); ui.reconfigure ( st.nextToken(), st.hasMoreTokens () ? st.nextToken () : null ); } Redirect(); void setUI(UI ui, Element e); void actionPerformed(ActionEvent ev); public UI ui; }### Answer:
@Test public void testActionPerformedThrowsNoSuchElementException() throws Throwable { try { new Redirect().actionPerformed(new ActionEvent("", 100, "", 100L, 1000)); fail("Expected NoSuchElementException to be thrown"); } catch (NoSuchElementException ex) { assertNull(ex.getMessage(), "ex.getMessage()"); } }
@Test public void testActionPerformedThrowsNullPointerException() throws Throwable { try { new Redirect().actionPerformed(new ActionEvent(Long.valueOf(0L), 100, null, 100L, 1000)); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"String.length()\" because \"str\" is null", ex.getMessage(), "ex.getMessage()"); } } }
@Test public void testActionPerformedThrowsNullPointerException1() throws Throwable { try { new Redirect().actionPerformed(new ActionEvent("", 100, "testRedirectParam3", 100L, 1000)); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.ui.UI.reconfigure(String, String)\" because \"this.ui\" is null", ex.getMessage(), "ex.getMessage()"); } } }
@Test public void testActionPerformedThrowsNullPointerException2() throws Throwable { try { new Redirect().actionPerformed(new ActionEvent("", 100, "testRedirect\rParam3", 100L, 1000)); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.ui.UI.reconfigure(String, String)\" because \"this.ui\" is null", ex.getMessage(), "ex.getMessage()"); } } }