微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法杀死某些突变

如何解决无法杀死某些突变

我在杀死某些突变时遇到了一些麻烦,我不明白为什么。

这是我正在测试的课程

@Configuration
@EnableScheduling
public class TasksDeclaration {

  private static final Logger LOGGER = LoggerFactory.getLogger(TasksDeclaration.class);

  private final ErrorLogFactory errorLogFactory;
  private final AccountConnectorClient accountConnectorClient;
  private final PublisherClient publisherClient;

  @Scheduled(cron = "${task.health-check.cron}")
  public void verifyServicesAreRunning() {
    domainservicestatus domainservicestatus = domainservicestatus.INSTANCE;

    try {
      LOGGER.info("Verifying health status of - starting");

      domainservicestatus.setAccountConnectorUp(isAccountConnectorRunning());
      domainservicestatus.setPublisherUp(isPublisherRunning());

      LOGGER.info("Verifying health status - done - services are running");
    } catch (RetryableException ex) {
      domainservicestatus.setAccountConnectorUp(false);
      domainservicestatus.setPublisherUp(false);
    }
  }

  private boolean isAccountConnectorRunning() {
    ResponseEntity<HealthStatus> response = accountConnectorClient.HeathCheck();

    return (response.getBody().getStatus().equals(SERVICE_UP));
  }

  private boolean isPublisherRunning() {
    ResponseEntity<HealthStatus> response = publisherClient.HeathCheck();

    return (response.getBody().getStatus().equals(SERVICE_UP));
  }

}

这是我的测试方法

@Test
void verifyServicesAreRunning_error() throws FeignException {
  when(accountConnectorClient.HeathCheck()).thenThrow(new RetryableException(500,"message",Request.HttpMethod.GET,new Date(),DataFixture.getRequest()));

  tasksDeclaration.verifyServicesAreRunning();

  verify(accountConnectorClient).HeathCheck();

  assertFalse(domainservicestatus.INSTANCE.isAccountConnectorUp());
  assertFalse(domainservicestatus.INSTANCE.isPublisherUp());
}

Pit 测试覆盖率报告告诉我,尽管调用删除,我的 catch 语句中的 2 行仍然存在。我遗漏了什么/没有测试什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。