Search in sources :

Example 6 with EasyMockSupport

use of org.easymock.EasyMockSupport in project Payara by payara.

the class WeldContextListenerTest method testcontextInitialized.

@Test
public void testcontextInitialized() throws Exception {
    EasyMockSupport mockSupport = new EasyMockSupport();
    ELResolver elResolver = mockSupport.createMock(ELResolver.class);
    ExpressionFactory expressionFactory = mockSupport.createMock(ExpressionFactory.class);
    StandardContext servletContext = new StandardContext();
    servletContext.getServletContext();
    ServletContextEvent servletContextEvent = mockSupport.createMock(ServletContextEvent.class);
    BeanManager beanManager = mockSupport.createMock(BeanManager.class);
    JspApplicationContextImpl jspApplicationContext = new JspApplicationContextImpl(servletContext);
    expect(beanManager.getELResolver()).andReturn(elResolver);
    expect(beanManager.wrapExpressionFactory(isA(ExpressionFactory.class))).andReturn(expressionFactory);
    mockSupport.replayAll();
    WeldContextListener weldContextListener = getWeldContextListener(beanManager, jspApplicationContext);
    weldContextListener.contextInitialized(servletContextEvent);
    assertSame(expressionFactory, jspApplicationContext.getExpressionFactory());
    validateJspApplicationContext(jspApplicationContext, elResolver);
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) ELResolver(javax.el.ELResolver) ExpressionFactory(javax.el.ExpressionFactory) JspApplicationContextImpl(org.apache.jasper.runtime.JspApplicationContextImpl) StandardContext(org.apache.catalina.core.StandardContext) BeanManager(javax.enterprise.inject.spi.BeanManager) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 7 with EasyMockSupport

use of org.easymock.EasyMockSupport in project Payara by payara.

the class WeldContextListenerTest method testcontextDestroyed.

@Test
public void testcontextDestroyed() throws Exception {
    EasyMockSupport mockSupport = new EasyMockSupport();
    BeanManager beanManager = mockSupport.createMock(BeanManager.class);
    mockSupport.replayAll();
    WeldContextListener weldContextListener = getWeldContextListener(beanManager, null);
    Class<?> clazz = LocalWeldContextListener.class.getSuperclass();
    Field beanManagerField = clazz.getDeclaredField("beanManager");
    beanManagerField.setAccessible(true);
    assertNotNull(beanManagerField.get(weldContextListener));
    weldContextListener.contextDestroyed(null);
    assertNull(beanManagerField.get(weldContextListener));
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : Field(java.lang.reflect.Field) EasyMockSupport(org.easymock.EasyMockSupport) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.junit.Test)

Example 8 with EasyMockSupport

use of org.easymock.EasyMockSupport in project easymock by easymock.

the class MockBuilderTest method testWithMockSupport.

@Test
public void testWithMockSupport() {
    EasyMockSupport support = new EasyMockSupport();
    MockBuilderTest a = support.createMockBuilder(MockBuilderTest.class).addMockedMethods("myMethod", "toString").createMock(MockType.NICE);
    expect(a.myMethod(2)).andReturn(1);
    support.replayAll();
    assertEquals(1, a.myMethod(2));
    assertEquals(0, a.myMethod(3));
    support.verifyAll();
    assertEquals("EasyMock for class org.easymock.tests2.MockBuilderTest", a.toString());
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) Test(org.junit.Test)

Aggregations

EasyMockSupport (org.easymock.EasyMockSupport)8 Test (org.junit.Test)7 BeanManager (javax.enterprise.inject.spi.BeanManager)2 Application (com.sun.enterprise.deployment.Application)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 ELResolver (javax.el.ELResolver)1 ExpressionFactory (javax.el.ExpressionFactory)1 Contextual (javax.enterprise.context.spi.Contextual)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 InitialContext (javax.naming.InitialContext)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 StandardContext (org.apache.catalina.core.StandardContext)1 JspApplicationContextImpl (org.apache.jasper.runtime.JspApplicationContextImpl)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 WeldUtils (org.glassfish.weld.connector.WeldUtils)1 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1