Run FormTester in WicketTester, "enter" the incorrect value in your TextField, submit the FormTester form and
a) check the model, invalid values โโwill not be written to the model
b) check for error messages
But to tell the truth and suggest my thoughts that were not asked, I donโt quite understand why you want to check it ... The adding method is part of the gate and should not be checked by you, but the Developers of the gate. The same applies to the PatternValidator class, however you can check your pattern. As for the rest of the code in this method ... This is trivial and does not justify the verification as far as I know.
Application (as mentioned in the commentary, there are simpler ways to make sure that a method has been called than to call FormTester. This snippet was just hacked into this editor, so no IDE checks which ones are applied):
private Boolean methodCalled = false; @Test public void testSomething() { WicketTester tester = new WicketTester(); tester.startComponentInPage(new StringTextBoxPanel("id", "someText") { @Override public void addPatternValidator(String pattern) { methodCalled = true; } }); AssertTrue(methodCalled); }
source share