I’m creating a mock class for a Lexer object, and I think I may need to do some refactoring. I have two options:
- Create an interface
Lexer, and rename the currentLexerto something likeRealLexer. HaveMockLexerimplementLexer, and method calls take anything of typeLexer. I dislike that my preciousLexerclass is now renamed to something that has no meaning if you don’t know that there’s a mock class. - Create an interface
LexerInterface(which I already dislike, since it hasInterfacein its name), but allowing myself to keep the currentLexerthe way it is.MockLexerthen implementsLexerInterface. Another downside is that method calls takeLexerInterfaceas params.
Both options smell bad to me, so I figured I’d let standards decide for me. Has anyone had experience with this?
I’d definitely vote for using
Lexeras your interface name. How about adding some information about how or why your implementation does its thing as part of the name?E.g.:
StringParsingLexerTokenizingLexerSingleThreadedLexer{ThirdPartyLibraryName}DelegatingLexerAlso, do you really need to be explicitly constructing a
MockLexer? Using a framework like Mockito can make your testing considerably easier and faster; You can get started as easily as: