return new MockSettingsImpl().defaultAnswer(RETURNS_DEFAULTS);
@Override public MockSettings verboseLogging() { if (!invocationListenersContainsType(VerboseMockInvocationLogger.class)) { invocationListeners(new VerboseMockInvocationLogger()); } return this; }
@Override public <T> MockCreationSettings<T> build(Class<T> typeToMock) { return validatedSettings(typeToMock, (CreationSettings<T>) this); }
@Override public MockCreationSettings getMockSettings() { final MockSettingsImpl mockSettings = new MockSettingsImpl(); mockSettings.setMockName(new MockNameImpl(mock.getName())); mockSettings.setTypeToMock(mock); return mockSettings; }
@Test public void jsr107ListenerFactoryInitFailureClosesExpiryLoader() throws Exception { ExpiryPolicy expiryPolicy = mock(ExpiryPolicy.class, new MockSettingsImpl<>().extraInterfaces(Closeable.class)); CacheLoader<Object, Object> loader = mock(CacheLoader.class, new MockSettingsImpl<>().extraInterfaces(Closeable.class)); MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); configuration.setExpiryPolicyFactory(factoryOf(expiryPolicy)) .setReadThrough(true) .setCacheLoaderFactory(factoryOf(loader)) .addCacheEntryListenerConfiguration(new ThrowingCacheEntryListenerConfiguration()); try { merger.mergeConfigurations("cache", configuration); fail("Loader factory should have thrown"); } catch (CacheException mce) { verify((Closeable) expiryPolicy).close(); verify((Closeable) loader).close(); } }
MockHandler() { this(new MockSettingsImpl()); }
settings.defaultAnswer(Mockito.CALLS_REAL_METHODS); settings.setMockName(new MockNameImpl(mockName)); settings.setTypeToMock(type);
private static <T> CreationSettings<T> validatedSettings(Class<T> typeToMock, CreationSettings<T> source) { MockCreationValidator validator = new MockCreationValidator(); validator.validateType(typeToMock); validator.validateExtraInterfaces(typeToMock, source.getExtraInterfaces()); validator.validateMockedType(typeToMock, source.getSpiedInstance()); //TODO SF - add this validation and also add missing coverage // validator.validateDelegatedInstance(classToMock, settings.getDelegatedInstance()); CreationSettings<T> settings = new CreationSettings<T>(source); settings.setMockName(new MockNameImpl(source.getName(), typeToMock)); settings.setTypeToMock(typeToMock); settings.setExtraInterfaces(prepareExtraInterfaces(source)); return settings; }
@Test public void jsr107LoaderInitFailureClosesExpiry() throws Exception { ExpiryPolicy expiryPolicy = mock(ExpiryPolicy.class, new MockSettingsImpl<>().extraInterfaces(Closeable.class)); MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); Factory<CacheLoader<Object, Object>> factory = throwingFactory(); configuration.setExpiryPolicyFactory(factoryOf(expiryPolicy)) .setReadThrough(true) .setCacheLoaderFactory(factory); try { merger.mergeConfigurations("cache", configuration); fail("Loader factory should have thrown"); } catch (CacheException mce) { verify((Closeable) expiryPolicy).close(); } }
private MockSettings createMockSettings() { MockSettings mockSettings = new MockSettingsImpl(); if (extraInterfaces != null && extraInterfaces.length > 0) { mockSettings.extraInterfaces(extraInterfaces); } if (defaultAnswer != null) { mockSettings.defaultAnswer(defaultAnswer.get()); } else { mockSettings.defaultAnswer(Answers.RETURNS_DEFAULTS.get()); } if (mockName != null) { mockSettings.name(mockName); } return mockSettings; }
private static <T> CreationSettings<T> validatedSettings(Class<T> typeToMock, CreationSettings<T> source) { MockCreationValidator validator = new MockCreationValidator(); validator.validateType(typeToMock); validator.validateExtraInterfaces(typeToMock, source.getExtraInterfaces()); validator.validateMockedType(typeToMock, source.getSpiedInstance()); //TODO SF - add this validation and also add missing coverage // validator.validateDelegatedInstance(classToMock, settings.getDelegatedInstance()); validator.validateConstructorUse(source.isUsingConstructor(), source.getSerializableMode()); //TODO SF - I don't think we really need CreationSettings type //TODO do we really need to copy the entire settings every time we create mock object? it does not seem necessary. CreationSettings<T> settings = new CreationSettings<T>(source); settings.setMockName(new MockNameImpl(source.getName(), typeToMock)); settings.setTypeToMock(typeToMock); settings.setExtraInterfaces(prepareExtraInterfaces(source)); return settings; }
Object returnValueFor(Class<?> clazz) { if (!mockitoCore.isTypeMockable(clazz)) { return null; } return mockitoCore.mock(clazz, new MockSettingsImpl().defaultAnswer(this)); } }
public MockSettings verboseLogging() { if (!invocationListenersContainsType(VerboseMockInvocationLogger.class)) { invocationListeners(new VerboseMockInvocationLogger()); } return this; }
public MockCreationSettings<T> confirm(Class<T> typeToMock) { return validatedSettings(typeToMock, this); }
return new MockSettingsImpl().defaultAnswer(RETURNS_DEFAULTS);
public MockSettings verboseLogging() { if (!invocationListenersContainsType(VerboseMockInvocationLogger.class)) { invocationListeners(new VerboseMockInvocationLogger()); } return this; }
Object returnValueFor(Class<?> clazz) { if (!ClassImposterizer.INSTANCE.canImposterise(clazz)) { return null; } return mockitoCore.mock(clazz, new MockSettingsImpl().defaultAnswer(this)); } }
/** * Gets the default settings of Mockito * * @return the default settings of Mockito */ private MockSettingsImpl getDefaultSettings() { return (MockSettingsImpl) new MockSettingsImpl().defaultAnswer(Mockito.RETURNS_DEFAULTS); }
return new MockSettingsImpl().defaultAnswer(RETURNS_DEFAULTS);
Object returnValueFor(Class<?> clazz) { if (!ClassImposterizer.INSTANCE.canImposterise(clazz)) { return null; } return mockitoCore.mock(clazz, new MockSettingsImpl().defaultAnswer(this)); } }