@Override public LoadTimeWeaver getLoadTimeWeaver() { return mock(LoadTimeWeaver.class); } }
@Override public LoadTimeWeaver getLoadTimeWeaver() { return mock(LoadTimeWeaver.class); } }
@Bean @Override public CacheErrorHandler errorHandler() { return mock(CacheErrorHandler.class); }
@Before @SuppressWarnings("unchecked") public void setUp() { adaptee = mock(Future.class); adapter = new FutureAdapter<String, Integer>(adaptee) { @Override protected String adapt(Integer adapteeResult) throws ExecutionException { return adapteeResult.toString(); } }; }
@Test public void testDefaultBeginTransaction() throws Exception { TransactionDefinition definition = new DefaultTransactionDefinition(); EntityManager entityManager = mock(EntityManager.class); EntityTransaction entityTx = mock(EntityTransaction.class); given(entityManager.getTransaction()).willReturn(entityTx); dialect.beginTransaction(entityManager, definition); }
@Before public void setup() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect"); mockCollaborator = mock(AfterReturningAdviceBindingCollaborator.class); afterAdviceAspect.setCollaborator(mockCollaborator); testBeanProxy = (ITestBean) ctx.getBean("testBean"); assertTrue(AopUtils.isAopProxy(testBeanProxy)); // we need the real target too, not just the proxy... this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget(); }
@Before public void setup() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBeanProxy = (ITestBean) ctx.getBean("testBean"); assertTrue(AopUtils.isAopProxy(testBeanProxy)); // we need the real target too, not just the proxy... testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget(); AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect"); mockCollaborator = mock(AdviceBindingCollaborator.class); beforeAdviceAspect.setCollaborator(mockCollaborator); }
private CacheManagerMock() { this.cacheNames = new ArrayList<>(); this.cacheManager = mock(CacheManager.class); given(cacheManager.getCacheNames()).willReturn(cacheNames); }
@Bean public Cache mockCache() { Cache cache = mock(Cache.class); given(cache.getName()).willReturn("test"); return cache; }
@Test(expected = IllegalArgumentException.class) public void toResourceRegionInputStreamResource() { InputStreamResource resource = mock(InputStreamResource.class); HttpRange range = HttpRange.createByteRange(0, 9); range.toResourceRegion(resource); }
@Test public void resolveWithPointToPointQueueSession() throws Exception { Queue expectedDestination = new StubQueue(); Session session = mock(QueueSession.class); given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination); testResolveDestination(session, expectedDestination, false); }
@Test public void getFileUnsupported() throws IOException { Path path = mock(Path.class); given(path.normalize()).willReturn(path); given(path.toFile()).willThrow(new UnsupportedOperationException()); PathResource resource = new PathResource(path); thrown.expect(FileNotFoundException.class); resource.getFile(); }
@Test public void beginsInModifiedState() throws Exception { Resource resource = mock(Resource.class); ResourceScriptSource scriptSource = new ResourceScriptSource(resource); assertTrue(scriptSource.isModified()); }
@Override public <K, V> Cache<K, V> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext) { String cacheName = cacheInvocationContext.getCacheName(); Cache<K, V> mock = mock(Cache.class); given(mock.getName()).willReturn(cacheName); return mock; }
@Test // SPR-13620 @SuppressWarnings("unchecked") public void writeContentInputStreamThrowingNullPointerException() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource resource = mock(Resource.class); InputStream in = mock(InputStream.class); given(resource.getInputStream()).willReturn(in); given(in.read(any())).willThrow(NullPointerException.class); converter.write(resource, MediaType.APPLICATION_OCTET_STREAM, outputMessage); assertEquals(0, outputMessage.getHeaders().getContentLength()); }
@Test public void defaultCacheNameWithDefaults() { Method method = ReflectionUtils.findMethod(Object.class, "toString"); CacheDefaults mock = mock(CacheDefaults.class); given(mock.cacheName()).willReturn(""); assertEquals("java.lang.Object.toString()", source.determineCacheName(method, mock, "")); }
@Test public void toTextMessageWithJsonViewClass() throws JMSException { converter.setTargetType(MessageType.TEXT); TextMessage textMessageMock = mock(TextMessage.class); MyAnotherBean bean = new MyAnotherBean("test", "lengthy description"); given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock); converter.toMessage(bean, sessionMock, Summary.class); verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName()); verify(sessionMock).createTextMessage("{\"name\":\"test\"}"); }
@Test public void testCreatesVanillaConnectionFactoryIfNoConnectionManagerHasBeenConfigured() throws Exception { final Object CONNECTION_FACTORY = new Object(); ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class); given(managedConnectionFactory.createConnectionFactory()).willReturn(CONNECTION_FACTORY); LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean(); factory.setManagedConnectionFactory(managedConnectionFactory); factory.afterPropertiesSet(); assertEquals(CONNECTION_FACTORY, factory.getObject()); }
@Test public void simpleApplicationEventMulticasterWithErrorHandler() { @SuppressWarnings("unchecked") ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class); ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext()); SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster(); smc.setErrorHandler(TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER); smc.addApplicationListener(listener); willThrow(new RuntimeException()).given(listener).onApplicationEvent(evt); smc.multicastEvent(evt); }
@Test public void resolveArgumentBindingDisabled() throws Exception { String name = "noBindAttr"; Object target = new TestBean(); this.container.addAttribute(name, target); StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name); WebDataBinderFactory factory = mock(WebDataBinderFactory.class); given(factory.createBinder(this.request, target, name)).willReturn(dataBinder); this.processor.resolveArgument(this.paramBindingDisabledAttr, this.container, this.request, factory); assertFalse(dataBinder.isBindInvoked()); assertTrue(dataBinder.isValidateInvoked()); }