I have a GWT app, where I take input from textbox, check that value for a regex, and if it matches, then I add that text to the table. When I give any correct input for e.g. "Hello", it works perfectly fine.
However when I try to use mockito to test this method, and pass the same string "Hello" through 'when,thenreturn ' method, then it fails the regex. cant understand whats hapenning The mocking code is :
when(mockView.getNewSymbolText()).thenReturn("Hello");
when(mockView.flexTableRowCount()).thenReturn(1);
stockWatcherPresenter.addStock();
assertEquals(1,stockWatcherPresenter.getStockSize());
Any help will be appreciated.
CodePudding user response:
Your regex does not include lowercase letters. If you want to include lowercase then add that range to the character class definition. Otherwise, it is behaving as expected.
EDIT - I suppose the real question is why doesn't it fail when you run the application? My suspicion is that the symbol text is being forced to upper case by the production code whereas your mocked behavior is producing mixed case.
CodePudding user response:
Regex doesn't allow lowercase chars. Change from A-Z
to A-Za-z
and it should behave as you expect. I guess the form capitalize the input in some way that does not happen in your test code.