Skip to content

it-crowd/mock-contexts-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mock contexts

This extension starts mock contexts for your tests. Currently it supports ConversationContext, ViewScopedContext and additionally FacesContext.

Usage

Just add impl module to classpath and run test either from IDE or maven.

<dependency>
    <groupid>pl.itcrowd.mock-contexts-extension</groupid>
    <artifactid>mock-contexts-extension-api</artifactid>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupid>pl.itcrowd.mock-contexts-extension</groupid>
    <artifactid>mock-contexts-extension-impl</artifactid>
    <version>1.0.0</version>
    <scope>runtime</scope>
</dependency>

Now you can annotate your test method with @ConversationScopeRequired or @ViewScopeRequired to activate those contexts.

If your tests depend on FacesContext.getCurrentInstance() then you can provide mock that will be registered as current instance:

@FacesContextRequired
@Test
public void facesContextNr1Availabile1()
{
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Assert.assertNotNull(facesContext);
    Assert.assertSame(mock, facesContext);
    Assert.assertEquals(attributes, facesContext.getAttributes());
}

@MockFacesContextProducer
public FacesContext mockFacesContext()
{
    if (mock == null) {
        mock = mock(FacesContext.class);
    }
    return mock;
}

About

Arquillian extension for contexts control

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages