EditableParameterInputVerifier extends InputVerifier { @Override public boolean verify(JComponent input) { if (!(input instanceof JTextField)) { return true; } String textValue = ((JTextField)input).getText(); if (!isNumeric(textValue)) { markAsInvalid(input); return false; } if (isBoundParameter()) { double doubleValue = Double.parseDouble(textValue); if (doubleValue < getParameterMinValue() || doubleValue > getParameterMaxValue()) { markAsInvalid(input); return false; } } markAsValid(input); return true; } EditableParameterInputVerifier(Parameter parameterToVerifyAgainst); @Override boolean verify(JComponent input);  }
@Test public void testWithBoundParameterEmptyString() { initialiseWithBoundParameter(); setTextValue(""); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithBoundParameterBlankString() { initialiseWithBoundParameter(); setTextValue(" "); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithBoundParameterInvalidString() { initialiseWithBoundParameter(); setTextValue("Not a number"); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithBoundParameterBelowMinBoundString() { initialiseWithBoundParameter(); setTextValue("-0.1"); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithBoundParameterAboveMaxBoundString() { initialiseWithBoundParameter(); setTextValue("10.1"); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithBoundParameterNearMinBoundString() { initialiseWithBoundParameter(); setTextValue("0.001"); result = classToBeTested.verify(textField); assertFieldMarkedValid(); }
@Test public void testWithBoundParameterNearMaxBoundString() { initialiseWithBoundParameter(); setTextValue("9.999"); result = classToBeTested.verify(textField); assertFieldMarkedValid(); }
@Test public void testWithBoundParameterOnMinBoundString() { initialiseWithBoundParameter(); setTextValue("0.0"); result = classToBeTested.verify(textField); assertFieldMarkedValid(); }
@Test public void testWithBoundParameterOnMaxBoundString() { initialiseWithBoundParameter(); setTextValue("10.0"); result = classToBeTested.verify(textField); assertFieldMarkedValid(); }
@Test public void testWithUnboundParameterEmptyString() { initialiseWithUnboundParameter(); setTextValue(""); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithUnboundParameterBlankString() { initialiseWithUnboundParameter(); setTextValue(" "); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithUnboundParameterInvalidString() { initialiseWithUnboundParameter(); setTextValue("Not a number"); result = classToBeTested.verify(textField); assertFieldMarkedInvalid(); }
@Test public void testWithUnboundParameterValidPositiveString() { initialiseWithUnboundParameter(); setTextValue("123.45"); result = classToBeTested.verify(textField); assertFieldMarkedValid(); }
@Test public void testWithUnboundParameterValidNegativeString() { initialiseWithUnboundParameter(); setTextValue("-123.45"); result = classToBeTested.verify(textField); assertFieldMarkedValid(); }