0

This is one of the rare cases in which the official documentation of an API is severely lacking synchronization with the actual provided API.

So, the jcabi-manifests API documentation clearly states here that manifest entries can be statically mocked using the utility class Manifests. Unfortunately, the static methods described in the mentioned page - e.g. inject(), snapshot(), revert() - are missing from the actual API.

Has anybody been able to use the manifest mocking feature supposedly being delivered with jcabi-manifests? If yes, how?

4

2 回答 2

0

看起来文档确实有点混乱。您需要版本 0.8.2。这是所有模拟功能仍然存在的地方。但是最新版本中存在更好的模拟方式。不要使用静态方法,而是将一个实例传递Manifests给您的类并模拟它的整个实例。在最新版本中,我们摆脱了静态方法,因为它们很难在并发线程中进行测试。如果您有更多问题,请向 Github 提交工单,我们会尽力提供帮助:https ://github.com/jcabi/jcabi-manifests/issues

于 2014-12-30T08:05:43.670 回答
0

对于更新版本的Manifests(当前为 1.1),解决方案是使用Manifests.DEFAULT可操作的地图。因此,对于我的测试,我所做的是添加我想要的属性,然后将其作为拆卸方法的一部分删除:

  @After
  public void tearDown() {
    Manifests.DEFAULT.remove("my-client-version");
  }

  @Test
  public void testGetClientVersion() {
    Manifests.DEFAULT.put("my-client-version", "1.2.3");
    final String actual = VersionUtils.getClientVersion();
    assertThat(actual).isEqualTo("1.2.3");
  }
于 2021-07-16T17:18:32.387 回答