6
I’m trying to mock a Static method, but Powermock requires the use of a specific Runner (Powermockrunner) for the Static mock to work!
And for Demoiselle to work, you need to start Weld with Demoisellerunner, but the Junit API only accepts a single Runner.
@RunWith(PowerMockRunner.class) //DemoiselleRunner.class
@PrepareForTest(Fabrica.class)
public class MeuBCTest {
@Inject
private PrimeiroBC primeiroBC; //Não injeta com o PowerMockRunner
private SegundoBC segundoBC;
@Before
public void setUp() {
primeiroBC = Mockito.spy(primeiroBC);
segundoBC = Mockito.mock(SegundoBC.class);
}
@Test
public void testCamposObrigatoriosComSucesso() {
PowerMockito.mockStatic(Fabrica.class);
PowerMockito.when(Fabrica.createSegundoBC()).thenReturn(segundoBC);
primeiroBC.fazerAlgo(); //Internamente este método chama o Fabrica.createSegundoBC() para executar outra operação.
//verificações
}
}
Initially I thought of creating my own Runner extending from Powermockrunner and adding Weld as it is done in Demoisellerunner.
There are some settings in Demoiselle or Powermock so you don’t need to create another Runner?
It worked in part... we still needed to add the annotatio @Powermockignore({"org.mockito. *"}) in the class due to a bug (https://groups.google.com/forum/#! topic/powermock/Rupbz4ufg-w).
– user3297199
@user3297199 But after adding this annotation the test was successfully run?
– utluiz
Not yet due to Powermock, it apparently runs the tests on a separate thread from where Demoiselle starts Weld. CDI is not working. Have any hints?
– user3297199
Regarding the frequency of Demoiselle commits, the project has been on Github for a long time and no longer on SF.net SVN. You can find the updated data here: https://github.com/demoiselle/framework/network
– zyc
@zyc I evaluated the framework at the end of 2013 and at the time found no references to Github. Actually this was not the only reason I didn’t use it. I’m accessing the framework’s official website now and there’s a lot of outdated information. It took me about 20 minutes to find out about the latest releases and I couldn’t even access the Quickstart guide in the documentation. You really need to browse the Sourceforge directories to find this information?
– utluiz