Language (String goodName, String badName) { NamesValidator v = createMock(NamesValidator.class); //noinspection ConstantConditions expect(v.isIdentifier(eq(goodName), anyObject())).andStubReturn(true); //noinspection ConstantConditions expect(v.isIdentifier(eq(badName), anyObject())).andStubReturn(false); replay(v); Language l = createMock(Language.class); expect(l.getID()).andStubReturn("MOCK_LANGUAGE_DIALECT"); expect(l.getBaseLanguage()).andStubReturn(null); expect(l.getUserData(anyObject())).andReturn(null).anyTimes(); l.putUserData(anyObject(), anyObject()); expectLastCall().anyTimes(); expect(l.putUserDataIfAbsent(anyObject(), anyObject())).andAnswer(() -> getCurrentArguments()[1]).anyTimes(); // return second parameter replay(l); LanguageNamesValidation.INSTANCE.addExplicitExtension(l, v, getTestRootDisposable()); return l; }