Created
May 14, 2012 15:00
-
-
Save jeffbicca/2694450 to your computer and use it in GitHub Desktop.
Por que o Weld/DemoiselleRunner? sobrescreve o mock que setei, fazendo novamente o Inject, sendo que o bean já inicializou?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@BusinessController | |
public class MeuBC implements Serializable { | |
@Inject MeuDAO meuDAO; | |
public List<JPABean> listaJPABeans() { | |
return meuDAO.findAll(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ViewController | |
public class MeuMB implements Serializable { | |
@Inject MeuBC meuBC; | |
public List<JPABean> getListaJPABeans() { | |
return meuBC.listaJPABeans(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.mockito.Mockito.doReturn; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.MockitoAnnotations.initMocks; | |
@RunWith(DemoiselleRunner.class) | |
public class MeuMBTest { | |
@Inject MeuMB meuMB; | |
@Mock MeuBC meuBCMock; | |
@Before | |
public void setup() { | |
initMocks(this); | |
} | |
@Test | |
public void deveListarJPABeans() { | |
doReturn(Collections.EMPTY_LIST).when(meuBCMock).listaJPABeans(); | |
meuMB.meuBC = meuBCMock; // setou corretamente meuBCMock no atributo | |
meuMB.getListaJPABeans(); // antes de chamar este método, o Weld intercepta a chamada e injeta uma instância que ele produziu, sobrescrevendo a que eu setei acima. | |
verify(meuBCMock).listaJPABeans(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment