I use the powermockito for my test. Why @Autowired fields are not initialized
up vote
0
down vote
favorite
I use the powermockito for my test. Why @Autowired fields are not initialized. Here is a sample code.
@PrepareForTest(EntityGenerator.class)
@RunWith(PowerMockRunner.class)
public class LoadingEsbContractorsTaskTest {
@Autowired
private SrrServiceContainer srrServiceContainer;
@PersistenceContext
EntityManager em;
@Before
public void setUp() throws Exception {
createMocking();
}
private void createMocking() throws Exception {
PowerMockito.spy(EntityGenerator.class);
PowerMockito.doReturn("mock").when(EntityGenerator.class, "generateUniqueNameByEntityClass", EsbContractor.class);
}
In this case private SrrServiceContainer and private EntityManager em fields have value of null but the mocked method "generateUniqueNameByEntityClass" works good.
How can I do initializ those filds, how did it work before applying the stub.
powermock
add a comment |
up vote
0
down vote
favorite
I use the powermockito for my test. Why @Autowired fields are not initialized. Here is a sample code.
@PrepareForTest(EntityGenerator.class)
@RunWith(PowerMockRunner.class)
public class LoadingEsbContractorsTaskTest {
@Autowired
private SrrServiceContainer srrServiceContainer;
@PersistenceContext
EntityManager em;
@Before
public void setUp() throws Exception {
createMocking();
}
private void createMocking() throws Exception {
PowerMockito.spy(EntityGenerator.class);
PowerMockito.doReturn("mock").when(EntityGenerator.class, "generateUniqueNameByEntityClass", EsbContractor.class);
}
In this case private SrrServiceContainer and private EntityManager em fields have value of null but the mocked method "generateUniqueNameByEntityClass" works good.
How can I do initializ those filds, how did it work before applying the stub.
powermock
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I use the powermockito for my test. Why @Autowired fields are not initialized. Here is a sample code.
@PrepareForTest(EntityGenerator.class)
@RunWith(PowerMockRunner.class)
public class LoadingEsbContractorsTaskTest {
@Autowired
private SrrServiceContainer srrServiceContainer;
@PersistenceContext
EntityManager em;
@Before
public void setUp() throws Exception {
createMocking();
}
private void createMocking() throws Exception {
PowerMockito.spy(EntityGenerator.class);
PowerMockito.doReturn("mock").when(EntityGenerator.class, "generateUniqueNameByEntityClass", EsbContractor.class);
}
In this case private SrrServiceContainer and private EntityManager em fields have value of null but the mocked method "generateUniqueNameByEntityClass" works good.
How can I do initializ those filds, how did it work before applying the stub.
powermock
I use the powermockito for my test. Why @Autowired fields are not initialized. Here is a sample code.
@PrepareForTest(EntityGenerator.class)
@RunWith(PowerMockRunner.class)
public class LoadingEsbContractorsTaskTest {
@Autowired
private SrrServiceContainer srrServiceContainer;
@PersistenceContext
EntityManager em;
@Before
public void setUp() throws Exception {
createMocking();
}
private void createMocking() throws Exception {
PowerMockito.spy(EntityGenerator.class);
PowerMockito.doReturn("mock").when(EntityGenerator.class, "generateUniqueNameByEntityClass", EsbContractor.class);
}
In this case private SrrServiceContainer and private EntityManager em fields have value of null but the mocked method "generateUniqueNameByEntityClass" works good.
How can I do initializ those filds, how did it work before applying the stub.
powermock
powermock
asked Nov 21 at 8:29
Андрей
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407930%2fi-use-the-powermockito-for-my-test-why-autowired-fields-are-not-initialized%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown