### Question:
MinMaxValueHelper { public static void setupMinMaxHandlers(final HTMLInputElement input) { input.onfocusout = (e) -> onFocusOut(input); input.onkeydown = (e) -> onKeyDown(input); input.onkeyup = (e) -> onKeyUp(input); }  static void setupMinMaxHandlers(final HTMLInputElement input); static Integer toInteger(final String value,
                                    final Integer defaultValue);  }### Answer:
@Test public void testSetupMinMaxHandlersOnKeyDownWhenValueIsValid() { input.value = "50"; input.max = "100"; input.min = "-100"; setupMinMaxHandlers(input); final Object result = input.onkeydown.onInvoke(event); assertEquals(result, true); verify(input).setAttribute(OLD_ATTR, "50"); }
@Test public void testSetupMinMaxHandlersOnKeyDownWhenValueIsNotValid() { input.value = "200"; input.max = "100"; input.min = "-100"; setupMinMaxHandlers(input); final Object result = input.onkeydown.onInvoke(event); assertEquals(result, true); verify(input, never()).setAttribute(anyString(), anyString()); }
@Test public void testSetupMinMaxHandlersOnKeyUpWhenNewValueIsValid() { final String newValue = "2"; final String oldValue = "42"; input.value = newValue; input.max = "100"; input.min = "-100"; setupMinMaxHandlers(input); when(input.getAttribute(OLD_ATTR)).thenReturn(oldValue); final Object result = input.onkeyup.onInvoke(event); final String actualValue = input.value; assertEquals(result, true); assertEquals(actualValue, newValue); }
@Test public void testSetupMinMaxHandlersOnKeyUpWhenNewValueIsNotValid() { final String newValue = "150"; final String oldValue = "42"; input.value = newValue; input.max = "100"; input.min = "-100"; setupMinMaxHandlers(input); when(input.getAttribute(OLD_ATTR)).thenReturn(oldValue); final Object result = input.onkeyup.onInvoke(event); final String actualValue = input.value; assertEquals(result, true); assertEquals(actualValue, oldValue); }
@Test public void testSetupMinMaxHandlersOnFocusOutWhenNewValueIsValid() { final String newValue = "2"; final String oldValue = "42"; input.value = newValue; input.max = "100"; input.min = "-100"; setupMinMaxHandlers(input); when(input.getAttribute(OLD_ATTR)).thenReturn(oldValue); final Object result = input.onfocusout.onInvoke(event); final String actualValue = input.value; assertEquals(result, true); assertEquals(actualValue, newValue); }
@Test public void testSetupMinMaxHandlersOnFocusOutWhenNewValueIsNotValid() { final String newValue = "150"; final String oldValue = "42"; input.value = newValue; input.max = "100"; input.min = "-100"; setupMinMaxHandlers(input); when(input.getAttribute(OLD_ATTR)).thenReturn(oldValue); final Object result = input.onfocusout.onInvoke(event); final String actualValue = input.value; assertEquals(result, true); assertEquals(actualValue, oldValue); }