Java Examples for org.assertj.core.util.Lists

The following java examples will help you to understand the usage of org.assertj.core.util.Lists. These source code samples are taken from different open source projects.

Example 1
Project: camunda-bpm-assert-master  File: ProcessInstanceAssert.java View source code
private ProcessInstanceAssert isWaitingAt(final String[] activityIds, boolean isWaitingAt, boolean exactly) {
    ProcessInstance current = getExistingCurrent();
    Assertions.assertThat(activityIds).overridingErrorMessage("Expecting list of activityIds not to be null, not to be empty and not to contain null values: %s.", Lists.newArrayList(activityIds)).isNotNull().isNotEmpty().doesNotContainNull();
    final List<String> activeActivityIds = runtimeService().getActiveActivityIds(actual.getId());
    final String message = "Expecting %s " + (isWaitingAt ? "to be waiting at " + (exactly ? "exactly " : "") + "%s, " : "NOT to be waiting at %s, ") + "but it is actually waiting at %s.";
    ListAssert<String> assertion = (ListAssert<String>) Assertions.assertThat(activeActivityIds).overridingErrorMessage(message, toString(current), Lists.newArrayList(activityIds), activeActivityIds);
    if (exactly) {
        if (isWaitingAt) {
            assertion.containsOnly(activityIds);
        } else {
            throw new UnsupportedOperationException();
        // "isNotWaitingAtExactly" is unsupported
        }
    } else {
        if (isWaitingAt) {
            assertion.contains(activityIds);
        } else {
            assertion.doesNotContain(activityIds);
        }
    }
    return this;
}
Example 2
Project: aws-ec2-start-stop-tools-master  File: StartStopServiceTest.java View source code
@Test
public void testProcessAllSectionsUnknownSection() {
    final ProgramOptions programOptions = new ProgramOptions(true, false, false, false, Lists.newArrayList(SECTION_1));
    Mockito.doReturn(null).when(configurationService).getConfiguredSections(SECTION_1);
    Assertions.assertThat(startStopService.processAllSections(programOptions)).isTrue();
    Mockito.verify(configurationService).getConfiguredSections(SECTION_1);
}
Example 3
Project: saos-master  File: TestPersistenceObjectFactory.java View source code
/**
     * Creates {@link DeletedJudgment}s for the given judgment ids
     */
@Transactional
public List<DeletedJudgment> createDeletedJudgments(long... judgmentIds) {
    Preconditions.checkNotNull(judgmentIds);
    List<DeletedJudgment> deletedJudgments = Lists.newArrayList();
    for (long judgmentId : judgmentIds) {
        DeletedJudgment deletedJudgment = TestInMemoryDeletedJudgmentFactory.createDeletedJudgment(judgmentId);
        save(deletedJudgment);
        deletedJudgments.add(deletedJudgment);
    }
    return deletedJudgments;
}
Example 4
Project: seed-master  File: HalRepresentationTest.java View source code
@Test
public void test_hal_link_serialization() throws Exception {
    HalRepresentation halRepresentation = new HalRepresentation();
    halRepresentation.link("objects", "/pok");
    halRepresentation.embedded("objects", Lists.newArrayList(new Person("toto")));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectMapper objectMapper = new ObjectMapper();
    outputStream.write(objectMapper.writeValueAsBytes(halRepresentation));
    outputStream.flush();
    Assertions.assertThat(outputStream.toString()).isEqualTo(EXPECTED);
}
Example 5
Project: assertj-core-master  File: SoftAssertionsTest.java View source code
@SuppressWarnings("unchecked")
@Test
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() throws URISyntaxException {
    try {
        softly.assertThat(BigDecimal.ZERO).isEqualTo(BigDecimal.ONE);
        softly.assertThat(Boolean.FALSE).isTrue();
        softly.assertThat(false).isTrue();
        softly.assertThat(new boolean[] { false }).isEqualTo(new boolean[] { true });
        softly.assertThat(new Byte((byte) 0)).isEqualTo((byte) 1);
        softly.assertThat((byte) 2).inHexadecimal().isEqualTo((byte) 3);
        softly.assertThat(new byte[] { 4 }).isEqualTo(new byte[] { 5 });
        softly.assertThat(new Character((char) 65)).isEqualTo(new Character((char) 66));
        softly.assertThat((char) 67).isEqualTo((char) 68);
        softly.assertThat(new char[] { 69 }).isEqualTo(new char[] { 70 });
        softly.assertThat(new StringBuilder("a")).isEqualTo(new StringBuilder("b"));
        softly.assertThat(Object.class).isEqualTo(String.class);
        softly.assertThat(parseDatetime("1999-12-31T23:59:59")).isEqualTo(parseDatetime("2000-01-01T00:00:01"));
        softly.assertThat(new Double(6.0d)).isEqualTo(new Double(7.0d));
        softly.assertThat(8.0d).isEqualTo(9.0d);
        softly.assertThat(new double[] { 10.0d }).isEqualTo(new double[] { 11.0d });
        softly.assertThat(new File("a")).overridingErrorMessage("expected:<File(b)> but was:<File(a)>").isEqualTo(new File("b"));
        softly.assertThat(new Float(12f)).isEqualTo(new Float(13f));
        softly.assertThat(14f).isEqualTo(15f);
        softly.assertThat(new float[] { 16f }).isEqualTo(new float[] { 17f });
        softly.assertThat(new ByteArrayInputStream(new byte[] { (byte) 65 })).hasSameContentAs(new ByteArrayInputStream(new byte[] { (byte) 66 }));
        softly.assertThat(new Integer(20)).isEqualTo(new Integer(21));
        softly.assertThat(22).isEqualTo(23);
        softly.assertThat(new int[] { 24 }).isEqualTo(new int[] { 25 });
        softly.assertThat((Iterable<String>) Lists.newArrayList("26")).isEqualTo(Lists.newArrayList("27"));
        softly.assertThat(Lists.newArrayList("28").iterator()).contains("29");
        softly.assertThat(Lists.newArrayList("30")).isEqualTo(Lists.newArrayList("31"));
        softly.assertThat(new Long(32L)).isEqualTo(new Long(33L));
        softly.assertThat(34L).isEqualTo(35L);
        softly.assertThat(new long[] { 36L }).isEqualTo(new long[] { 37L });
        softly.assertThat(Maps.mapOf(MapEntry.entry("38", "39"))).isEqualTo(Maps.mapOf(MapEntry.entry("40", "41")));
        softly.assertThat(new Short((short) 42)).isEqualTo(new Short((short) 43));
        softly.assertThat((short) 44).isEqualTo((short) 45);
        softly.assertThat(new short[] { (short) 46 }).isEqualTo(new short[] { (short) 47 });
        softly.assertThat("48").isEqualTo("49");
        softly.assertThat(new Object() {

            @Override
            public String toString() {
                return "50";
            }
        }).isEqualTo(new Object() {

            @Override
            public String toString() {
                return "51";
            }
        });
        softly.assertThat(new Object[] { new Object() {

            @Override
            public String toString() {
                return "52";
            }
        } }).isEqualTo(new Object[] { new Object() {

            @Override
            public String toString() {
                return "53";
            }
        } });
        final IllegalArgumentException illegalArgumentException = new IllegalArgumentException("IllegalArgumentException message");
        softly.assertThat(illegalArgumentException).hasMessage("NullPointerException message");
        softly.assertThatThrownBy(new ThrowingCallable() {

            @Override
            public void call() throws Exception {
                throw new Exception("something was wrong");
            }
        }).hasMessage("something was good");
        softly.assertThat(Maps.mapOf(MapEntry.entry("54", "55"))).contains(MapEntry.entry("1", "2"));
        softly.assertThat(LocalTime.of(12, 00)).isEqualTo(LocalTime.of(13, 00));
        softly.assertThat(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC)).isEqualTo(OffsetTime.of(13, 0, 0, 0, ZoneOffset.UTC));
        softly.assertThat(Optional.of("not empty")).isEqualTo("empty");
        softly.assertThat(OptionalInt.of(0)).isEqualTo(1);
        softly.assertThat(OptionalDouble.of(0.0)).isEqualTo(1.0);
        softly.assertThat(OptionalLong.of(0L)).isEqualTo(1L);
        softly.assertThat(new URI("http://assertj.org")).hasPort(8888);
        softly.assertThat(CompletableFuture.completedFuture("done")).hasFailed();
        softly.assertThat((Predicate<String>)  s -> s.equals("something")).accepts("something else");
        softly.assertThat((IntPredicate)  s -> s == 1).accepts(2);
        softly.assertThat((LongPredicate)  s -> s == 1).accepts(2);
        softly.assertThat((DoublePredicate)  s -> s == 1).accepts(2);
        softly.assertAll();
        fail("Should not reach here");
    } catch (SoftAssertionError e) {
        List<String> errors = e.getErrors();
        assertThat(errors).hasSize(52);
        assertThat(errors.get(0)).startsWith("expected:<[1]> but was:<[0]>");
        assertThat(errors.get(1)).startsWith("expected:<[tru]e> but was:<[fals]e>");
        assertThat(errors.get(2)).startsWith("expected:<[tru]e> but was:<[fals]e>");
        assertThat(errors.get(3)).startsWith("expected:<[[tru]e]> but was:<[[fals]e]>");
        assertThat(errors.get(4)).startsWith("expected:<[1]> but was:<[0]>");
        assertThat(errors.get(5)).startsWith("expected:<0x0[3]> but was:<0x0[2]>");
        assertThat(errors.get(6)).startsWith("expected:<[[5]]> but was:<[[4]]>");
        assertThat(errors.get(7)).startsWith("expected:<'[B]'> but was:<'[A]'>");
        assertThat(errors.get(8)).startsWith("expected:<'[D]'> but was:<'[C]'>");
        assertThat(errors.get(9)).startsWith("expected:<['[F]']> but was:<['[E]']>");
        assertThat(errors.get(10)).startsWith("expected:<[b]> but was:<[a]>");
        assertThat(errors.get(11)).startsWith("expected:<java.lang.[String]> but was:<java.lang.[Object]>");
        assertThat(errors.get(12)).startsWith("expected:<[2000-01-01T00:00:01].000> but was:<[1999-12-31T23:59:59].000>");
        assertThat(errors.get(13)).startsWith("expected:<[7].0> but was:<[6].0>");
        assertThat(errors.get(14)).startsWith("expected:<[9].0> but was:<[8].0>");
        assertThat(errors.get(15)).startsWith("expected:<[1[1].0]> but was:<[1[0].0]>");
        assertThat(errors.get(16)).startsWith("expected:<File(b)> but was:<File(a)>");
        assertThat(errors.get(17)).startsWith("expected:<1[3].0f> but was:<1[2].0f>");
        assertThat(errors.get(18)).startsWith("expected:<1[5].0f> but was:<1[4].0f>");
        assertThat(errors.get(19)).startsWith("expected:<[1[7].0f]> but was:<[1[6].0f]>");
        assertThat(errors.get(20)).startsWith(format("%nInputStreams do not have same content:%n%n" + "Changed content at line 1:%n" + "expecting:%n" + "  [\"B\"]%n" + "but was:%n" + "  [\"A\"]%n"));
        assertThat(errors.get(21)).startsWith("expected:<2[1]> but was:<2[0]>");
        assertThat(errors.get(22)).startsWith("expected:<2[3]> but was:<2[2]>");
        assertThat(errors.get(23)).startsWith("expected:<[2[5]]> but was:<[2[4]]>");
        assertThat(errors.get(24)).startsWith("expected:<[\"2[7]\"]> but was:<[\"2[6]\"]>");
        assertThat(errors.get(25)).startsWith(format("%nExpecting:%n" + " <[\"28\"]>%n" + "to contain:%n" + " <[\"29\"]>%n" + "but could not find:%n" + " <[\"29\"]>%n"));
        assertThat(errors.get(26)).startsWith("expected:<[\"3[1]\"]> but was:<[\"3[0]\"]>");
        assertThat(errors.get(27)).startsWith("expected:<3[3]L> but was:<3[2]L>");
        assertThat(errors.get(28)).startsWith("expected:<3[5]L> but was:<3[4]L>");
        assertThat(errors.get(29)).startsWith("expected:<[3[7]L]> but was:<[3[6]L]>");
        assertThat(errors.get(30)).startsWith("expected:<{\"[40\"=\"41]\"}> but was:<{\"[38\"=\"39]\"}>");
        assertThat(errors.get(31)).startsWith("expected:<4[3]> but was:<4[2]>");
        assertThat(errors.get(32)).startsWith("expected:<4[5]> but was:<4[4]>");
        assertThat(errors.get(33)).startsWith("expected:<[4[7]]> but was:<[4[6]]>");
        assertThat(errors.get(34)).startsWith("expected:<\"4[9]\"> but was:<\"4[8]\">");
        assertThat(errors.get(35)).startsWith("expected:<5[1]> but was:<5[0]>");
        assertThat(errors.get(36)).startsWith("expected:<[5[3]]> but was:<[5[2]]>");
        assertThat(errors.get(37)).startsWith(format("%nExpecting message:%n" + " <\"NullPointerException message\">%n" + "but was:%n" + " <\"IllegalArgumentException message\">"));
        assertThat(errors.get(38)).startsWith(format("%nExpecting message:%n" + " <\"something was good\">%n" + "but was:%n" + " <\"something was wrong\">"));
        assertThat(errors.get(39)).startsWith(format("%nExpecting:%n" + " <{\"54\"=\"55\"}>%n" + "to contain:%n" + " <[MapEntry[key=\"1\", value=\"2\"]]>%n" + "but could not find:%n" + " <[MapEntry[key=\"1\", value=\"2\"]]>%n"));
        assertThat(errors.get(40)).startsWith("expected:<1[3]:00> but was:<1[2]:00>");
        assertThat(errors.get(41)).startsWith("expected:<1[3]:00Z> but was:<1[2]:00Z>");
        assertThat(errors.get(42)).startsWith("expected:<[\"empty\"]> but was:<[Optional[not empty]]>");
        assertThat(errors.get(43)).startsWith("expected:<[1]> but was:<[OptionalInt[0]]>");
        assertThat(errors.get(44)).startsWith("expected:<[1.0]> but was:<[OptionalDouble[0.0]]>");
        assertThat(errors.get(45)).startsWith("expected:<[1L]> but was:<[OptionalLong[0]]>");
        assertThat(errors.get(46)).contains("Expecting port of");
        assertThat(errors.get(47)).contains("to have failed");
        assertThat(errors.get(48)).startsWith(String.format("%nExpecting:%n  <given predicate>%n" + "to accept <\"something else\"> but it did not."));
        assertThat(errors.get(49)).startsWith(String.format("%nExpecting:%n  <given predicate>%n" + "to accept <2> but it did not."));
        assertThat(errors.get(50)).startsWith(String.format("%nExpecting:%n  <given predicate>%n" + "to accept <2L> but it did not."));
        assertThat(errors.get(51)).startsWith(String.format("%nExpecting:%n  <given predicate>%n" + "to accept <2.0> but it did not."));
    }
}
Example 6
Project: cereebro-master  File: CompositeSnitchRegistryTest.java View source code
@Test
public void getAll() {
    Snitch s1 = new StaticSnitch(URI.create("fake://1"));
    Snitch s2 = new StaticSnitch(URI.create("fake://2"));
    ArrayList<SnitchRegistry> registries = Lists.newArrayList(StaticSnitchRegistry.of(s1), StaticSnitchRegistry.of(s2));
    SnitchRegistry composite = CompositeSnitchRegistry.of(registries);
    List<Snitch> expected = Arrays.asList(s1, s2);
    Assert.assertEquals(expected, composite.getAll());
}
Example 7
Project: mapstruct-master  File: FieldsMappingTest.java View source code
@Test
public void shouldMapSourceToTarget() throws Exception {
    Source source = new Source();
    source.normalInt = 4;
    source.normalList = Lists.newArrayList(10, 11, 12);
    source.fieldOnlyWithGetter = 20;
    Target target = SourceTargetMapper.INSTANCE.toSource(source);
    assertThat(target).isNotNull();
    assertThat(target.finalInt).isEqualTo("10");
    assertThat(target.normalInt).isEqualTo("4");
    assertThat(target.finalList).containsOnly("1", "2", "3");
    assertThat(target.normalList).containsOnly("10", "11", "12");
    assertThat(target.privateFinalList).containsOnly(3, 4, 5);
    // +21 from the source getter and append 11 on the setter from the target
    assertThat(target.fieldWithMethods).isEqualTo("4111");
}
Example 8
Project: katharsis-core-master  File: ErrorResponseSerializerTest.java View source code
@Test
public void shouldSerializeMultipleErrorDataElements() throws Exception {
    ErrorResponse responseWithoutSource = ErrorResponse.builder().setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500).setErrorData(Lists.newArrayList(ErrorDataMother.fullyPopulatedErrorData(), ErrorDataMother.fullyPopulatedErrorData())).build();
    String result = sut.writeValueAsString(responseWithoutSource);
    assertThatJson(result).node("errors[0]").isPresent().node("errors[1]").isPresent();
}
Example 9
Project: director-spi-master  File: AbstractConfigurationPropertyTest.java View source code
@Test
public void testValidValueLocalization() {
    List<String> validValues = Lists.newArrayList();
    validValues.add("testVal1");
    validValues.add("testVal2");
    validValues.add("testVal3");
    TestConfigurationProperty testConfigurationProperty = new TestConfigurationProperty("configKey", Property.Type.STRING, "name", false, ConfigurationProperty.Widget.TEXT, "defaultValue", "defaultDescription", "defaultErrorMessage", validValues, false, false);
    List<ConfigurationPropertyValue> localizedValues = testConfigurationProperty.getValidValues(new TestLocalizer(Locale.getDefault(), ""));
    assertThat(localizedValues).hasSize(3);
    assertThat(localizedValues.get(0).getValue()).isEqualTo("testVal1");
    assertThat(localizedValues.get(0).getLabel()).isEqualTo("testLabel1");
    assertThat(localizedValues.get(1).getValue()).isEqualTo("testVal2");
    assertThat(localizedValues.get(1).getLabel()).isEqualTo("testLabel2");
    assertThat(localizedValues.get(2).getValue()).isEqualTo("testVal3");
    assertThat(localizedValues.get(2).getLabel()).isEqualTo("Unknown");
}
Example 10
Project: datasource-proxy-master  File: DefaultQueryLogEntryCreatorTest.java View source code
@Test
public void getLogEntryForStatement() throws Exception {
    Method method = Object.class.getMethod("toString");
    Object result = new Object();
    ExecutionInfo executionInfo = ExecutionInfoBuilder.create().dataSourceName("foo").elapsedTime(100).method(method).result(result).statementType(StatementType.STATEMENT).success(true).batch(false).batchSize(0).build();
    QueryInfo queryInfo = QueryInfoBuilder.create().query("select 1").build();
    DefaultQueryLogEntryCreator creator = new DefaultQueryLogEntryCreator();
    String entry = creator.getLogEntry(executionInfo, Lists.newArrayList(queryInfo), true);
    assertThat(entry).isEqualTo("Name:foo, Time:100, Success:True, Type:Statement, Batch:False, QuerySize:1, BatchSize:0, Query:[\"select 1\"], Params:[()]");
    // check multiline
    creator.setMultiline(true);
    entry = creator.getLogEntry(executionInfo, Lists.newArrayList(queryInfo), true);
    assertThat(entry).isEqualTo("" + LINE_SEPARATOR + "Name:foo, Time:100, Success:True" + LINE_SEPARATOR + "Type:Statement, Batch:False, QuerySize:1, BatchSize:0" + LINE_SEPARATOR + "Query:[\"select 1\"]" + LINE_SEPARATOR + "Params:[()]");
}
Example 11
Project: spring-master  File: MyBatisBatchItemWriterTest.java View source code
@Test
public void testZeroBatchResultShouldThrowException() {
    List<Employee> employees = Arrays.asList(new Employee(), new Employee());
    List<BatchResult> batchResults = Lists.emptyList();
    given(mockSqlSessionTemplate.flushStatements()).willReturn(batchResults);
    assertThrows(InvalidDataAccessResourceUsageException.class, () -> writer.write(employees));
}
Example 12
Project: termsuite-core-master  File: EnglishWindEnergySpec.java View source code
@Override
protected List<String> getSyntacticMatchingRules() {
    return Lists.newArrayList("M-S-NN", "M-S-(A|N)NN", "M-I-EN-N|A", "M-I-NN-CA", "M-R2I-ANN", "M-ID-AN-CA", "M-PI-NN-P", "M-I-NN-N", "M-I-AN-N|A|R", "S-Ed-NN-PN", "S-Ed-NN-N", "S-Ed-NPN-CPN", "S-Ed-AN-PN", "S-Eg-NPN-A", "S-Eg-NPN-NC", "S-Eg-AN-(A|N)", "S-Eg-AN-R", "S-Eg-AN-AC", "S-EgD-NNN-A", "S-EgD-(A|N)N-A|N", "S-EgD-NN-R", "S-EgD2-(A|N)N-A|N", "S-I-AN-A", "S-I-AN-CA", "S-I-AN-(N|A)N|AA", "S-I-NN-(N|A)", "S-I1-NPN-PNC", "S-I2-NPN-A", "S-I2-ANN-N", "S-P-AAN-A", "S-P-ANN-N", "S-PEg-NN-NC", "S-PI-NN-PN", "S-PI-NN-CNP", "S-R1Eg-AN-N", "S-PI-AN-V", "S-PI-NN-P", "M-SD-(N|A)N", "S-R2I-NPN-P", "ANN-prefANN", "AAN-AprefAN", "S-R2D-NN1", "M-I2-(A|N)N-E", "M-R3I1-ANNN", "AN-prefAN");
}
Example 13
Project: spring-petclinic-master  File: VetControllerTests.java View source code
@Before
public void setup() {
    Vet james = new Vet();
    james.setFirstName("James");
    james.setLastName("Carter");
    james.setId(1);
    Vet helen = new Vet();
    helen.setFirstName("Helen");
    helen.setLastName("Leary");
    helen.setId(2);
    Specialty radiology = new Specialty();
    radiology.setId(1);
    radiology.setName("radiology");
    helen.addSpecialty(radiology);
    given(this.vets.findAll()).willReturn(Lists.newArrayList(james, helen));
}
Example 14
Project: glucosio-android-master  File: HelloActivityTest.java View source code
@Test
public void ShouldInitLanguageSpinner_WhenCreated() throws Exception {
    when(getLocaleHelper().getLocalesWithTranslation(any(Resources.class))).thenReturn(Lists.newArrayList("nl", "ru", "ua"));
    when(getLocaleHelper().getDisplayLanguage("nl")).thenReturn("Nederlandse");
    when(getLocaleHelper().getDisplayLanguage("ru")).thenReturn("Русский");
    when(getLocaleHelper().getDisplayLanguage("ua")).thenReturn("Українська");
    activity = Robolectric.buildActivity(HelloActivity.class).create().get();
    assertThat(activity.languageSpinner.getSpinner()).hasCount(3);
    assertThat(activity.languageSpinner.getSpinner()).hasItemAtPosition(0, "Nederlandse");
    assertThat(activity.languageSpinner.getSpinner()).hasItemAtPosition(1, "Русский");
    assertThat(activity.languageSpinner.getSpinner()).hasItemAtPosition(2, "Українська");
}
Example 15
Project: sonar-gerrit-plugin-master  File: ReviewInputTest.java View source code
@Test
public void shouldEmptyTheComments() {
    ReviewInput reviewInput = new ReviewInput();
    ArrayList<ReviewFileComment> list = Lists.newArrayList();
    list.add(new ReviewFileComment());
    reviewInput.addComments(KEY_COMMENT1, list);
    assertEquals(1, reviewInput.size());
    reviewInput.emptyComments();
    assertEquals(0, reviewInput.size());
}
Example 16
Project: robolectric-master  File: ShadowCameraParametersTest.java View source code
@Test
public void testSetSupportedFocusModes() {
    shadowParameters.setSupportedFocusModes("foo", "bar");
    assertThat(parameters.getSupportedFocusModes()).isEqualTo(Lists.newArrayList("foo", "bar"));
    shadowParameters.setSupportedFocusModes("baz");
    assertThat(parameters.getSupportedFocusModes()).isEqualTo(Lists.newArrayList("baz"));
}
Example 17
Project: JsonPath-master  File: ProviderInTest.java View source code
@Test
public void testJsonPathQuotesJackson() throws Exception {
    final Configuration jackson = Configuration.builder().jsonProvider(new JacksonJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
    final DocumentContext ctx = JsonPath.using(jackson).parse(JSON);
    final List<String> doubleQuoteEqualsResult = ctx.read(DOUBLE_QUOTES_EQUALS_FILTER);
    assertEquals(Lists.newArrayList("bar"), doubleQuoteEqualsResult);
    final List<String> singleQuoteEqualsResult = ctx.read(SINGLE_QUOTES_EQUALS_FILTER);
    assertEquals(doubleQuoteEqualsResult, singleQuoteEqualsResult);
    final List<String> doubleQuoteInResult = ctx.read(DOUBLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, doubleQuoteEqualsResult);
    final List<String> singleQuoteInResult = ctx.read(SINGLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, singleQuoteInResult);
}
Example 18
Project: ddf-master  File: SortedQueryMonitorTest.java View source code
@Before
public void setUp() throws Exception {
    cachingFederationStrategy = mock(CachingFederationStrategy.class);
    completionService = mock(CompletionService.class);
    queryRequest = mock(QueryRequest.class);
    queryResponse = new QueryResponseImpl(queryRequest);
    query = mock(Query.class);
    // Enforce insertion order for testing purposes
    futures = new LinkedHashMap<>();
    for (int i = 0; i < 4; i++) {
        SourceResponse sourceResponseMock = null;
        Future futureMock = mock(Future.class);
        QueryRequest queryRequest = mock(QueryRequest.class);
        when(queryRequest.getSourceIds()).thenReturn(Collections.singleton("Source-" + i));
        switch(i) {
            case 1:
                sourceResponseMock = mock(SourceResponse.class);
                when(sourceResponseMock.getResults()).thenReturn(Lists.newArrayList(mock(Result.class), mock(Result.class), mock(Result.class)));
                when(sourceResponseMock.getHits()).thenReturn(3L);
                break;
            case 2:
                sourceResponseMock = mock(SourceResponse.class);
                when(sourceResponseMock.getResults()).thenReturn(Lists.newArrayList(mock(Result.class)));
                when(sourceResponseMock.getHits()).thenReturn(1L);
                break;
            case 3:
                sourceResponseMock = mock(SourceResponse.class);
                when(sourceResponseMock.getResults()).thenReturn(Lists.<Result>emptyList());
                when(sourceResponseMock.getHits()).thenReturn(0L);
                break;
        }
        when(futureMock.get()).thenReturn(sourceResponseMock);
        futures.put(futureMock, queryRequest);
    }
}
Example 19
Project: assertj-swing-master  File: KeyStrokeMappingProvider_de.java View source code
/**
   * @return the mapping between characters and {@code KeyStroke}s for locale {@code Locale.GERMAN}.
   */
@Override
@Nonnull
public Collection<KeyStrokeMapping> keyStrokeMappings() {
    List<KeyStrokeMapping> mappings = Lists.newArrayList(defaultMappings());
    mappings.add(mapping('0', VK_0, NO_MASK));
    mappings.add(mapping('=', VK_0, SHIFT_MASK));
    mappings.add(mapping('}', VK_0, ALT_GRAPH_MASK));
    mappings.add(mapping('1', VK_1, NO_MASK));
    mappings.add(mapping('!', VK_1, SHIFT_MASK));
    mappings.add(mapping('2', VK_2, NO_MASK));
    mappings.add(mapping('"', VK_2, SHIFT_MASK));
    mappings.add(mapping('�', VK_2, ALT_GRAPH_MASK));
    mappings.add(mapping('3', VK_3, NO_MASK));
    mappings.add(mapping('�', VK_3, SHIFT_MASK));
    mappings.add(mapping('�', VK_0, ALT_GRAPH_MASK));
    mappings.add(mapping('4', VK_4, NO_MASK));
    mappings.add(mapping('$', VK_4, SHIFT_MASK));
    mappings.add(mapping('5', VK_5, NO_MASK));
    mappings.add(mapping('%', VK_5, SHIFT_MASK));
    mappings.add(mapping('6', VK_6, NO_MASK));
    mappings.add(mapping('&', VK_6, SHIFT_MASK));
    mappings.add(mapping('7', VK_7, NO_MASK));
    mappings.add(mapping('/', VK_7, SHIFT_MASK));
    mappings.add(mapping('{', VK_7, ALT_GRAPH_MASK));
    mappings.add(mapping('8', VK_8, NO_MASK));
    mappings.add(mapping('(', VK_8, SHIFT_MASK));
    mappings.add(mapping('[', VK_8, ALT_GRAPH_MASK));
    mappings.add(mapping('9', VK_9, NO_MASK));
    mappings.add(mapping(')', VK_9, SHIFT_MASK));
    mappings.add(mapping(']', VK_9, ALT_GRAPH_MASK));
    mappings.add(mapping('a', VK_A, NO_MASK));
    mappings.add(mapping('A', VK_A, SHIFT_MASK));
    mappings.add(mapping('b', VK_B, NO_MASK));
    mappings.add(mapping('B', VK_B, SHIFT_MASK));
    mappings.add(mapping('^', VK_BACK_QUOTE, NO_MASK));
    mappings.add(mapping('�', VK_BACK_QUOTE, SHIFT_MASK));
    mappings.add(mapping('<', VK_BACK_SLASH, NO_MASK));
    mappings.add(mapping('>', VK_BACK_SLASH, SHIFT_MASK));
    mappings.add(mapping('|', VK_BACK_SLASH, ALT_GRAPH_MASK));
    mappings.add(mapping('c', VK_C, NO_MASK));
    mappings.add(mapping('C', VK_C, SHIFT_MASK));
    mappings.add(mapping('+', VK_CLOSE_BRACKET, NO_MASK));
    mappings.add(mapping('*', VK_CLOSE_BRACKET, SHIFT_MASK));
    mappings.add(mapping('~', VK_CLOSE_BRACKET, ALT_GRAPH_MASK));
    mappings.add(mapping(',', VK_COMMA, NO_MASK));
    mappings.add(mapping(';', VK_COMMA, SHIFT_MASK));
    mappings.add(mapping('d', VK_D, NO_MASK));
    mappings.add(mapping('D', VK_D, SHIFT_MASK));
    mappings.add(mapping('', VK_DELETE, NO_MASK));
    mappings.add(mapping('e', VK_E, NO_MASK));
    mappings.add(mapping('E', VK_E, SHIFT_MASK));
    mappings.add(mapping('�', VK_E, ALT_GRAPH_MASK));
    mappings.add(mapping('�', VK_EQUALS, NO_MASK));
    mappings.add(mapping('`', VK_EQUALS, SHIFT_MASK));
    mappings.add(mapping('f', VK_F, NO_MASK));
    mappings.add(mapping('F', VK_F, SHIFT_MASK));
    mappings.add(mapping('g', VK_G, NO_MASK));
    mappings.add(mapping('G', VK_G, SHIFT_MASK));
    mappings.add(mapping('h', VK_H, NO_MASK));
    mappings.add(mapping('H', VK_H, SHIFT_MASK));
    mappings.add(mapping('i', VK_I, NO_MASK));
    mappings.add(mapping('I', VK_I, SHIFT_MASK));
    mappings.add(mapping('j', VK_J, NO_MASK));
    mappings.add(mapping('J', VK_J, SHIFT_MASK));
    mappings.add(mapping('k', VK_K, NO_MASK));
    mappings.add(mapping('K', VK_K, SHIFT_MASK));
    mappings.add(mapping('l', VK_L, NO_MASK));
    mappings.add(mapping('L', VK_L, SHIFT_MASK));
    mappings.add(mapping('m', VK_M, NO_MASK));
    mappings.add(mapping('M', VK_M, SHIFT_MASK));
    mappings.add(mapping('�', VK_M, ALT_GRAPH_MASK));
    mappings.add(mapping('?', VK_SLASH, SHIFT_MASK));
    mappings.add(mapping('\\', VK_SLASH, ALT_GRAPH_MASK));
    mappings.add(mapping('n', VK_N, NO_MASK));
    mappings.add(mapping('N', VK_N, SHIFT_MASK));
    mappings.add(mapping('o', VK_O, NO_MASK));
    mappings.add(mapping('O', VK_O, SHIFT_MASK));
    mappings.add(mapping('p', VK_P, NO_MASK));
    mappings.add(mapping('P', VK_P, SHIFT_MASK));
    mappings.add(mapping('.', VK_PERIOD, NO_MASK));
    mappings.add(mapping(':', VK_PERIOD, SHIFT_MASK));
    mappings.add(mapping('q', VK_Q, NO_MASK));
    mappings.add(mapping('Q', VK_Q, SHIFT_MASK));
    mappings.add(mapping('@', VK_Q, ALT_GRAPH_MASK));
    mappings.add(mapping('r', VK_R, NO_MASK));
    mappings.add(mapping('R', VK_R, SHIFT_MASK));
    mappings.add(mapping('s', VK_S, NO_MASK));
    mappings.add(mapping('S', VK_S, SHIFT_MASK));
    mappings.add(mapping('-', VK_MINUS, NO_MASK));
    mappings.add(mapping('_', VK_MINUS, SHIFT_MASK));
    mappings.add(mapping(' ', VK_SPACE, NO_MASK));
    mappings.add(mapping('t', VK_T, NO_MASK));
    mappings.add(mapping('T', VK_T, SHIFT_MASK));
    mappings.add(mapping('u', VK_U, NO_MASK));
    mappings.add(mapping('U', VK_U, SHIFT_MASK));
    mappings.add(mapping('v', VK_V, NO_MASK));
    mappings.add(mapping('V', VK_V, SHIFT_MASK));
    mappings.add(mapping('w', VK_W, NO_MASK));
    mappings.add(mapping('W', VK_W, SHIFT_MASK));
    mappings.add(mapping('x', VK_X, NO_MASK));
    mappings.add(mapping('X', VK_X, SHIFT_MASK));
    mappings.add(mapping('y', VK_Y, NO_MASK));
    mappings.add(mapping('Y', VK_Y, SHIFT_MASK));
    mappings.add(mapping('z', VK_Z, NO_MASK));
    mappings.add(mapping('Z', VK_Z, SHIFT_MASK));
    return mappings;
}
Example 20
Project: verjson-master  File: ProxyStepComparatorTest.java View source code
@Test
public void sortTwoV1T1() throws Exception {
    List<ProxyStep> steps = Lists.newArrayList();
    steps.add(new ProxyStep(1L, validation));
    steps.add(new ProxyStep(1L, transformation));
    List<ProxyStep> expected = Lists.newArrayList();
    expected.add(new ProxyStep(1L, validation));
    expected.add(new ProxyStep(1L, transformation));
    assertSort(steps, expected);
}
Example 21
Project: objectlabkit-master  File: FxRateCalculatorImplTest.java View source code
@Test
public void testEurUsd() {
    FxRateCalculatorBuilder builder = new FxRateCalculatorBuilder().addRateSnapshot(new FxRateImpl(CurrencyPair.of("EUR", "USD"), null, true, BigDecimalUtil.bd("1.6"), BigDecimalUtil.bd("1.61"), //
    new JdkCurrencyProvider())).addRateSnapshot(new FxRateImpl(CurrencyPair.of("GBP", "CHF"), null, true, BigDecimalUtil.bd("2.1702"), BigDecimalUtil.bd("2.1707"), //
    new JdkCurrencyProvider())).addRateSnapshot(new FxRateImpl(CurrencyPair.of("EUR", "GBP"), null, true, BigDecimalUtil.bd("0.7374"), BigDecimalUtil.bd("0.7379"), //
    new JdkCurrencyProvider())).orderedCurrenciesForCross(//
    Lists.newArrayList("GBP"));
    final FxRateCalculator calc = new FxRateCalculatorImpl(builder);
    CurrencyPair target = CurrencyPair.of("EUR", "USD");
    final Optional<FxRate> fx = calc.findFx(target);
    assertThat(fx.isPresent()).isTrue();
    assertThat(fx.get().getCurrencyPair()).isEqualTo(target);
    assertThat(fx.get().getCrossCcy().isPresent()).isFalse();
    assertThat(fx.get().isMarketConvention()).isTrue();
    assertThat(fx.get().getBid()).isEqualByComparingTo("1.6");
    assertThat(fx.get().getAsk()).isEqualByComparingTo("1.61");
    final CurrencyAmount amountInUSD = fx.get().convertAmountUsingBidOrAsk(Cash.of("EUR", 1_000_000L));
    assertThat(amountInUSD.getCurrency()).isEqualTo("USD");
    assertThat(amountInUSD.getAmount()).isEqualByComparingTo("1600000");
    // I want to BUY 1m USD with Euros
    final CurrencyAmount amountBuyInUSD = fx.get().convertAmountUsingBidOrAsk(Cash.of("USD", 1_000_000L));
    assertThat(amountBuyInUSD.getCurrency()).isEqualTo("EUR");
    assertThat(amountBuyInUSD.getAmount()).isEqualByComparingTo("621118.01");
    CurrencyPair invTgt = target.createInverse();
    // order of the Currency Pair does NOT matter for conversions!
    final Optional<FxRate> fx2 = calc.findFx(invTgt);
    assertThat(fx2.isPresent()).isTrue();
    assertThat(fx2.get().getCurrencyPair()).isEqualTo(invTgt);
    assertThat(fx2.get().getCrossCcy().isPresent()).isFalse();
    assertThat(fx2.get().isMarketConvention()).isFalse();
    assertThat(fx2.get().getBid()).isEqualByComparingTo("0.621118012422");
    assertThat(fx2.get().getAsk()).isEqualByComparingTo("0.625");
    final CurrencyAmount amountInUSD2 = fx2.get().convertAmountUsingBidOrAsk(Cash.of("EUR", 1_000_000L));
    assertThat(amountInUSD2.getCurrency()).isEqualTo("USD");
    assertThat(amountInUSD2.getAmount()).isEqualByComparingTo("1600000");
    // I want to BUY 1m USD with Euros
    final CurrencyAmount amountBuyInUSD2 = fx2.get().convertAmountUsingBidOrAsk(Cash.of("USD", 1_000_000L));
    assertThat(amountBuyInUSD2.getCurrency()).isEqualTo("EUR");
    assertThat(amountBuyInUSD2.getAmount()).isEqualByComparingTo("621118.01");
}
Example 22
Project: cassandra-mesos-master  File: CassandraClusterStateTest.java View source code
@Test
public void allResourcesAvailableBeforeLaunchingExecutor() throws Exception {
    cleanState();
    final String role = "*";
    final Protos.Offer offer = Protos.Offer.newBuilder().setFrameworkId(frameworkId).setHostname("localhost").setId(Protos.OfferID.newBuilder().setValue(randomID())).setSlaveId(Protos.SlaveID.newBuilder().setValue("slave_1")).addResources(cpu(0.1, role)).addResources(mem(0.1, role)).addResources(disk(0.1, role)).addResources(ports(Lists.<Long>emptyList(), role)).build();
    final Marker marker = MarkerFactory.getMarker("offerId:" + offer.getId().getValue() + ",hostname:" + offer.getHostname());
    assertThat(cluster._getTasksForOffer(marker, offer)).isNull();
}
Example 23
Project: moonshine-master  File: ServicesTest.java View source code
@Test
public void shouldStartServicesInDependencyOrder() throws ConfigurationException {
    class ServiceA extends AbstractService {

        boolean started = false;

        @Override
        public void start() {
            started = true;
        }

        @Override
        public void stop() {
            started = false;
        }
    }
    class ServiceB extends AbstractService {

        @ImportService
        private ServiceA serviceA;

        @Override
        public void start() {
            assertThat(serviceA.started).isTrue();
        }

        @Override
        public void stop() {
            assertThat(serviceA.started).isTrue();
        }
    }
    try (Services services = Services.Factory.builder().configuration(new AbstractService() {

        @Override
        public Iterable<? extends Service> getSubServices() {
            return Lists.newArrayList(new ServiceB(), new ServiceA());
        }
    }).build()) {
        services.start();
    }
}
Example 24
Project: jmxtrans-master  File: ServerTests.java View source code
@Test
public void testConnectionRepoolingOk() throws Exception {
    @SuppressWarnings("unchecked") GenericKeyedObjectPool<JmxConnectionProvider, JMXConnection> pool = mock(GenericKeyedObjectPool.class);
    Server server = Server.builder().setHost("host.example.net").setPort("4321").setLocal(true).setPool(pool).build();
    MBeanServerConnection mBeanConn = mock(MBeanServerConnection.class);
    JMXConnection conn = mock(JMXConnection.class);
    when(conn.getMBeanServerConnection()).thenReturn(mBeanConn);
    when(pool.borrowObject(server)).thenReturn(conn);
    Query query = mock(Query.class);
    Iterable<ObjectName> objectNames = Lists.emptyList();
    when(query.queryNames(mBeanConn)).thenReturn(objectNames);
    server.execute(query);
    verify(pool, never()).invalidateObject(server, conn);
    InOrder orderVerifier = inOrder(pool);
    orderVerifier.verify(pool).borrowObject(server);
    orderVerifier.verify(pool).returnObject(server, conn);
}
Example 25
Project: MLDS-master  File: AffiliateResource_AffiliatesFilter_Test.java View source code
@Test
public void getAffiliatesCanReturnNoResults() throws Exception {
    PageImpl<Affiliate> matches = new PageImpl<>(Lists.<Affiliate>emptyList());
    when(affiliateRepository.findAll(Mockito.any(Pageable.class))).thenReturn(matches);
    restUserMockMvc.perform(get(Routes.AFFILIATES).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$", Matchers.hasSize(0)));
}
Example 26
Project: hawkular-metrics-master  File: HawkularReporterTest.java View source code
@Test
public void shouldReportPartialHistogram() {
    HawkularReporter reporter = HawkularReporter.builder(registry, "unit-test").setMetricComposition("my.histogram", Lists.newArrayList("mean", "median", "stddev")).useHttpClient( uri -> client).build();
    final Histogram histogram = registry.histogram("my.histogram");
    histogram.update(3);
    reporter.report();
    assertThat(client.getMetricsRestCalls()).hasSize(1);
    JSONObject metrics = new JSONObject(client.getMetricsRestCalls().get(0));
    assertThat(metrics.keySet()).containsOnly("gauges");
    JSONArray gaugesJson = metrics.getJSONArray("gauges");
    Map<String, Integer> values = StreamSupport.stream(gaugesJson.spliterator(), false).collect(toMap(idFromRoot::extract, valueFromRoot::extract));
    // Note: we extract int values here for simplicity, but actual values are double. The goal is not to test
    // Dropwizard algorithm for metrics generation, so we don't bother with accuracy.
    assertThat(values).containsOnly(entry("my.histogram.mean", 3), entry("my.histogram.median", 3), entry("my.histogram.stddev", 0));
    assertThat(client.getTagsRestCalls()).containsOnly(Pair.of("/gauges/my.histogram.mean/tags", "{\"histogram\":\"mean\"}"), Pair.of("/gauges/my.histogram.stddev/tags", "{\"histogram\":\"stddev\"}"), Pair.of("/gauges/my.histogram.median/tags", "{\"histogram\":\"median\"}"));
}
Example 27
Project: lmis-moz-mobile-master  File: VIARequisitionPresenterTest.java View source code
@Test
public void shouldInitViaKitsViewModel() throws Exception {
    RnRForm rnRForm = mock(RnRForm.class);
    when(mockRnrFormRepository.queryRnRForm(1L)).thenReturn(rnRForm);
    when(rnRForm.getRnrItems(IsKit.No)).thenReturn(new ArrayList<RnrFormItem>());
    RnrFormItem rnrKitItem1 = new RnrFormItemBuilder().setProduct(new ProductBuilder().setCode("SCOD10").build()).setReceived(100).setIssued(50).build();
    RnrFormItem rnrKitItem2 = new RnrFormItemBuilder().setProduct(new ProductBuilder().setCode("SCOD12").build()).setReceived(300).setIssued(110).build();
    List<RnrFormItem> rnrFormItems = Lists.newArrayList(rnrKitItem1, rnrKitItem2);
    when(rnRForm.getRnrItems(IsKit.Yes)).thenReturn(rnrFormItems);
    TestSubscriber<RnRForm> testSubscriber = new TestSubscriber<>();
    presenter.getRnrFormObservable(1L).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoErrors();
    assertEquals("50", presenter.getViaKitsViewModel().getKitsOpenedHF());
    assertEquals("100", presenter.getViaKitsViewModel().getKitsReceivedHF());
    assertEquals("110", presenter.getViaKitsViewModel().getKitsOpenedCHW());
    assertEquals("300", presenter.getViaKitsViewModel().getKitsReceivedCHW());
}
Example 28
Project: invesdwin-util-master  File: CachedHistoricalCacheQueryCore.java View source code
private List<Entry<FDate, V>> tryCachedGetPreviousEntriesIfAvailable(final IHistoricalCacheQueryInternalMethods<V> query, final FDate key, final int shiftBackUnits, final boolean filterDuplicateKeys) throws ResetCacheException {
    List<Entry<FDate, V>> result;
    if (!cachedPreviousEntries.isEmpty()) {
        result = cachedGetPreviousEntries(query, shiftBackUnits, key, filterDuplicateKeys);
        if (!result.isEmpty() && query.getAssertValue() != HistoricalCacheAssertValue.ASSERT_VALUE_WITH_FUTURE) {
            //fix when first withFuture and then withFutureNull is called on the cached result
            final Entry<FDate, V> firstResult = result.get(0);
            final Entry<FDate, V> assertedValue = query.getAssertValue().assertValue(delegate.getParent(), key, firstResult.getKey(), firstResult.getValue());
            if (assertedValue == null) {
                result = Lists.emptyList();
            }
        }
    } else {
        final List<Entry<FDate, V>> trailing = newEntriesList(query, shiftBackUnits, filterDuplicateKeys);
        result = defaultGetPreviousEntries(query, shiftBackUnits, key, trailing);
        updateCachedPreviousResult(query, shiftBackUnits, result, filterDuplicateKeys);
    }
    return result;
}
Example 29
Project: sonarqube-master  File: OrganizationDaoTest.java View source code
@Test
public void selectByQuery_with_empty_list_of_keys_returns_all() {
    insertOrganization(ORGANIZATION_DTO_1);
    insertOrganization(ORGANIZATION_DTO_2);
    OrganizationQuery organizationQuery = newOrganizationQueryBuilder().setKeys(Lists.emptyList()).build();
    assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))).extracting(OrganizationDto::getUuid).containsOnly(ORGANIZATION_DTO_1.getUuid(), ORGANIZATION_DTO_2.getUuid());
}
Example 30
Project: ovirt-engine-master  File: MultipleActionsRunnerBaseTest.java View source code
@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
    // needs to be implemented but is not called
    return Lists.newArrayList();
}
Example 31
Project: fabric8-master  File: HasMetadatasAssert.java View source code
protected AI assertThat(Iterable<R> result) {
    List<R> list = Lists.newArrayList(result);
    return createListAssert(list);
}
Example 32
Project: linkshortener-master  File: LinkServiceImplTest.java View source code
@Test
public void findShouldReturnLinks() {
    Page<LinkEntity> links = new PageImpl<>(Lists.newArrayList(new LinkEntity(), new LinkEntity()));
    given(linkRepository.findAll(any(Pageable.class))).willReturn(links);
    List<LinkEntity> result = linkService.find(1, 10);
    assertThat(result).hasSize(2);
}
Example 33
Project: tempto-master  File: GuiceTestContext.java View source code
@Override
public void close() {
    copyOf(children).forEach(GuiceTestContext::close);
    Lists.reverse(closeCallbacks).forEach( callback -> callback.testContextClosed(this));
    if (parent.isPresent()) {
        parent.get().children.remove(this);
    }
}
Example 34
Project: edison-microservice-master  File: MongoJobRepositoryTest.java View source code
@Test
public void shouldDeleteJobInfos() throws Exception {
    // given
    repo.createOrUpdate(someJobInfo("http://localhost/foo"));
    // when
    repo.deleteAll();
    // then
    assertThat(repo.findAll(), is(Lists.emptyList()));
}