mockito@Value设值

编程

@Component

public class MonitorManager {

@Value("${monitor.url}")

private String monitorUrl;

@Value("${monitor.userName}")

private String monitorUserName;

// 其他使用value的代码省略

}

@RunWith(PowerMockRunner.class)

@PowerMockRunnerDelegate(SpringRunner.class)

@PowerMockIgnore({"javax.net.*","javax.management.*", "javax.security.*", "javax.crypto.*", "org.mockito.*"})

public class MonitorManagerTest {

@InjectMocks

private MonitorManager monitorManager;

@Mock

private OAuth2RestTemplate restTemplate;

@Before

public void setUp() throws Exception {

ReflectionTestUtils.setField(monitorManager, "monitorUrl", "mock monitor url");

ReflectionTestUtils.setField(monitorManager, "monitorUserName", "mock userName");

}

}

 

以上是 mockito@Value设值 的全部内容, 来源链接: utcz.com/z/511166.html

回到顶部