org.assertj.core.data.Index Java Examples

The following examples show how to use org.assertj.core.data.Index. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeJavaCompilerSettingsTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void allSettings() {
    NativeJavaCompilerSettings settings = new NativeJavaCompilerSettings();
    settings.setDebug(true);
    settings.setWarnings(true);
    settings.setDeprecations(true);
    settings.setSourceEncoding("My-Custom-Encoding");
    settings.setSourceVersion("1.9");
    settings.setTargetVersion("1.9");
    List<String> options = settings.toOptionsList();

    assertThat(options).hasSize(9);
    assertThat(options).contains("-g");
    assertThat(options).contains("-Xlint:all");
    assertThat(options).contains("-deprecation");
    // check the order is correct, value of the option needs to be right after the option name
    assertThat(options).contains("1.9", Index.atIndex(options.indexOf("-source") + 1));
    assertThat(options).contains("1.9", Index.atIndex(options.indexOf("-target") + 1));
    assertThat(options).contains("My-Custom-Encoding", Index.atIndex(options.indexOf("-encoding") + 1));
}
 
Example #2
Source File: MatcherGeneratorTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyGenerate() {
  final MockSpecModel specModel =
      MockSpecModel.newBuilder()
          .contextClass(ClassName.bestGuess(DummyContext.class.getName()))
          .enclosedSpecModel(sEnclosedSpec)
          .build();

  final TypeSpecDataHolder holder = MatcherGenerator.generate(specModel);

  assertThat(holder.getFieldSpecs()).isEmpty();

  assertThat(holder.getMethodSpecs())
      .hasSize(1)
      .has(
          new Condition<MethodSpec>() {
            @Override
            public boolean matches(MethodSpec value) {
              return value.name.equals("matcher")
                  && value.returnType.toString().equals("Matcher");
            }
          },
          Index.atIndex(0));
}
 
Example #3
Source File: CoapTestBase.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
private void assertResponseContainsCommand(
        final CoapCommandEndpointConfiguration endpointConfiguration,
        final OptionSet responseOptions,
        final String expectedCommand,
        final String tenantId,
        final String commandTargetDeviceId) {

    assertThat(responseOptions.getLocationQuery())
        .as("location query must contain parameter [%s]", expectedCommand)
        .contains(expectedCommand);
    assertThat(responseOptions.getContentFormat()).isEqualTo(MediaTypeRegistry.APPLICATION_JSON);
    int idx = 0;
    assertThat(responseOptions.getLocationPath()).contains(CommandConstants.COMMAND_RESPONSE_ENDPOINT, Index.atIndex(idx++));
    if (endpointConfiguration.isSubscribeAsGateway()) {
        assertThat(responseOptions.getLocationPath()).contains(tenantId, Index.atIndex(idx++));
        assertThat(responseOptions.getLocationPath()).contains(commandTargetDeviceId, Index.atIndex(idx++));
    }
    // request ID
    assertThat(responseOptions.getLocationPath().get(idx))
        .as("location path must contain command request ID")
        .isNotNull();
}
 
Example #4
Source File: CoapTestBase.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
private void assertResponseContainsOneWayCommand(
        final CoapCommandEndpointConfiguration endpointConfiguration,
        final OptionSet responseOptions,
        final String expectedCommand,
        final String tenantId,
        final String commandTargetDeviceId) {

    assertThat(responseOptions.getLocationQuery())
        .as("response doesn't contain command")
        .contains(expectedCommand);
    assertThat(responseOptions.getContentFormat()).isEqualTo(MediaTypeRegistry.APPLICATION_JSON);
    assertThat(responseOptions.getLocationPath()).contains(CommandConstants.COMMAND_ENDPOINT, Index.atIndex(0));
    if (endpointConfiguration.isSubscribeAsGateway()) {
        assertThat(responseOptions.getLocationPath()).contains(tenantId, Index.atIndex(1));
        assertThat(responseOptions.getLocationPath()).contains(commandTargetDeviceId, Index.atIndex(2));
    }
}
 
Example #5
Source File: NativeJavaCompilerSettingsTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultSettings() {
    NativeJavaCompilerSettings settings = new NativeJavaCompilerSettings();
    List<String> options = settings.toOptionsList();
    assertThat(options).hasSize(6);
    assertThat(options).contains("-source", "-target", "-encoding");
    // check the order is correct, value of the option needs to be right after the option name
    assertThat(options).contains("1.8", Index.atIndex(options.indexOf("-source") + 1));
    assertThat(options).contains("1.8", Index.atIndex(options.indexOf("-target") + 1));
    assertThat(options).contains("UTF-8", Index.atIndex(options.indexOf("-encoding") + 1));
}
 
Example #6
Source File: MIMEMessageConverterTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
void convertToMimeShouldAddAttachmentAndMultipartAlternativeWhenOneAttachementAndTextAndHtmlBody() throws Exception {
    // Given
    MIMEMessageConverter sut = new MIMEMessageConverter(attachmentContentLoader);

    CreationMessage testMessage = CreationMessage.builder()
        .mailboxId("dead-bada55")
        .subject("subject")
        .from(DraftEmailer.builder().name("sender").build())
        .textBody("Hello all!")
        .htmlBody("Hello <b>all<b>!")
        .build();
    TextBody expectedTextBody = new BasicBodyFactory().textBody("Hello all!".getBytes(), StandardCharsets.UTF_8);
    TextBody expectedHtmlBody = new BasicBodyFactory().textBody("Hello <b>all<b>!".getBytes(), StandardCharsets.UTF_8);

    String expectedCID = "cid";
    String expectedMimeType = "image/png";
    String text = "123456";
    TextBody expectedAttachmentBody = new BasicBodyFactory().textBody(text.getBytes(), StandardCharsets.UTF_8);
    MessageAttachmentMetadata attachment = MessageAttachmentMetadata.builder()
        .attachment(AttachmentMetadata.builder()
            .attachmentId(AttachmentId.from("blodId"))
            .size(text.getBytes().length)
            .type(expectedMimeType)
            .build())
        .cid(Cid.from(expectedCID))
        .isInline(true)
        .build();
    when(attachmentContentLoader.load(attachment.getAttachment(), session))
        .thenReturn(new ByteArrayInputStream(text.getBytes()));

    // When
    Message result = sut.convertToMime(new ValueWithId.CreationMessageEntry(
        CreationMessageId.of("user|mailbox|1"), testMessage), ImmutableList.of(attachment), session);
    Multipart typedResult = (Multipart)result.getBody();

    assertThat(typedResult.getBodyParts())
        .hasSize(1)
        .extracting(entity -> (Multipart) entity.getBody())
        .flatExtracting(Multipart::getBodyParts)
        .satisfies(part -> {
            assertThat(part.getBody()).isInstanceOf(Multipart.class);
            assertThat(part.isMultipart()).isTrue();
            assertThat(part.getMimeType()).isEqualTo("multipart/alternative");
            assertThat(((Multipart)part.getBody()).getBodyParts()).hasSize(2);
            Entity textPart = ((Multipart)part.getBody()).getBodyParts().get(0);
            Entity htmlPart = ((Multipart)part.getBody()).getBodyParts().get(1);
            assertThat(textPart.getBody()).isEqualToComparingOnlyGivenFields(expectedTextBody, "content");
            assertThat(htmlPart.getBody()).isEqualToComparingOnlyGivenFields(expectedHtmlBody, "content");
        }, Index.atIndex(0))
        .satisfies(part -> {
            assertThat(part.getBody()).isEqualToComparingOnlyGivenFields(expectedAttachmentBody, "content");
            assertThat(part.getDispositionType()).isEqualTo("inline");
            assertThat(part.getMimeType()).isEqualTo(expectedMimeType);
            assertThat(part.getHeader().getField("Content-ID").getBody()).isEqualTo(expectedCID);
        }, Index.atIndex(1));
}