import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.mockito.ArgumentMatchers.any;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
@Slf4j
public class UserInfoKeeperTest {
@Autowired
@InjectMocks
private TestServiceImpl testServiceImpl;
@Autowired
@MockBean
SayHelloApi sayHelloApi;
@Before
public void before(){
MockitoAnnotations.initMocks(this);
Mockito.when(sayHelloApi.say(any(SayReq.class))).thenReturn("java world");
}
@Test
public void testMqConfig() {
String loginRes = testServiceImpl.login();
log.info("============================================="+loginRes);
}
}
|