org.mockito.Mockito.description()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.mockito.Mockito.description()方法的一些代码示例,展示了Mockito.description()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.description()方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:description

Mockito.description介绍

[英]Adds a description to be printed if verification fails.

verify(mock, description("This will print on failure")).someMethod("some arg");

[中]添加验证失败时要打印的说明

verify(mock, description("This will print on failure")).someMethod("some arg");

代码示例

代码示例来源:origin: info.solidsoft.mockito/mockito-java8

/**
   * Delegates call to {@link Mockito#description(String)}.
   *
   * @since 2.0.0
   */
  default VerificationMode description(String description) {
    return Mockito.description(description);
  }
}

代码示例来源:origin: szpak/mockito-java8

/**
   * Delegates call to {@link Mockito#description(String)}.
   *
   * @since 2.0.0
   */
  default VerificationMode description(String description) {
    return Mockito.description(description);
  }
}

代码示例来源:origin: trellis-ldp/trellis

private Stream<Executable> checkBinaryEntityResponse() {
    return Stream.of(
        () -> verify(mockResourceService, description("ResourceService::create not called!"))
              .create(any(Metadata.class), any(Dataset.class)),
        () -> verify(mockIoService, never().description("entity shouldn't be read!")).read(any(), any(), any()),
        () -> verify(mockBinaryService, description("content not set on binary service!"))
              .setContent(metadataArgument.capture(), any(InputStream.class)),
        () -> assertEquals(of("text/plain"), metadataArgument.getValue().getMimeType(), "Invalid content-type"),
        () -> assertTrue(metadataArgument.getValue().getIdentifier().getIRIString().startsWith("file:///"),
                 "Invalid binary ID!"));
  }
}

代码示例来源:origin: trellis-ldp/trellis

private Stream<Executable> verifyInteractions(final ResourceService svc) {
    return of(
        () -> verify(svc, never().description("Don't re-initialize the root if it already exists"))
            .create(any(Metadata.class), any(Dataset.class)),
        () -> verify(svc, never().description("Don't re-initialize the root if it already exists"))
            .replace(any(Metadata.class), any(Dataset.class)),
        () -> verify(svc, description("Verify that the root resource is fetched only once")).get(root));
  }
}

代码示例来源:origin: trellis-ldp/trellis

private Stream<Executable> checkRdfPut(final Response res) {
  return Stream.of(
      () -> assertAll("Check LDP type Link headers", checkLdpType(res, LDP.RDFSource)),
      () -> verify(mockBinaryService, never().description("Binary service shouldn't have been called!"))
             .setContent(any(BinaryMetadata.class), any(InputStream.class), any()),
      () -> verify(mockIoService, description("IOService should have been called with an RDF resource"))
             .read(any(InputStream.class), any(RDFSyntax.class), anyString()));
}

代码示例来源:origin: trellis-ldp/trellis

private Stream<Executable> checkBinaryPut(final Response res) {
    return Stream.of(
        () -> assertAll("Check LDP type Link headers", checkLdpType(res, LDP.NonRDFSource)),
        () -> verify(mockBinaryService, description("BinaryService should have been called to set content!"))
              .setContent(any(BinaryMetadata.class), any(InputStream.class)),
        () -> verify(mockIoService, never().description("IOService shouldn't have been called with a Binary!"))
              .read(any(InputStream.class), any(RDFSyntax.class), anyString()));
  }
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testInitializeoDeletedLdpResource() throws Exception {
  final ResourceService mockService = mock(ResourceService.class);
  when(mockBundler.getResourceService()).thenReturn(mockService);
  when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(DELETED_RESOURCE));
  when(mockService.create(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null));
  final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler);
  matcher.initialize();
  verify(mockService, description("A previously deleted root resource should be re-created upon initialization"))
    .create(any(Metadata.class), any(Dataset.class));
  verify(mockService, never().description("replace shouldn't be called when re-initializing a deleted root"))
    .replace(any(Metadata.class), any(Dataset.class));
  verify(mockService, description("Verify that the root resource is fetched only once")).get(root);
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testInitializeoNoLdpResource() throws Exception {
  final ResourceService mockService = mock(ResourceService.class);
  when(mockBundler.getResourceService()).thenReturn(mockService);
  when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(MISSING_RESOURCE));
  when(mockService.create(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null));
  final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler);
  matcher.initialize();
  verify(mockService, description("Re-create a missing root resource on initialization"))
    .create(any(Metadata.class), any(Dataset.class));
  verify(mockService, never().description("Don't try to replace a non-existent root on initialization"))
    .replace(any(Metadata.class), any(Dataset.class));
  verify(mockService, description("Verify that the root resource is fetched only once")).get(root);
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testInitializeExistingLdpResourceWithNoACL() throws Exception {
  final ResourceService mockService = mock(ResourceService.class);
  when(mockBundler.getResourceService()).thenReturn(mockService);
  when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(mockRootResource));
  when(mockRootResource.hasAcl()).thenReturn(false);
  when(mockService.replace(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null));
  final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler);
  matcher.initialize();
  verify(mockService, never().description("When re-initializing the root ACL, create should not be called"))
    .create(any(Metadata.class), any(Dataset.class));
  verify(mockService, description("Use replace when re-initializing the root ACL"))
    .replace(any(Metadata.class), any(Dataset.class));
  verify(mockService, description("Verify that the root resource is fetched only once")).get(root);
}

相关文章

微信公众号

最新文章

更多