I'm trying to mock a static method, but PowerMock requires the use of a specific Runner (PowerMockRunner) for mock static to work!
And for Demoiselle to work you have 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 about creating my own PowerMockRunner Runner by extending and adding Weld as it is done in DemoiselleRunner.
Is there a setup in Demoiselle or PowerMock so you do not need to create another Runner?