@Test public void executeLargeUpdates() { List<Integer> inputs = newArrayList(); for (int i = 0; i < 2010; i++) { inputs.add(i); } List<Integer> processed = newArrayList(); DatabaseUtils.executeLargeUpdates(inputs, input -> { assertThat(input.size()).isLessThanOrEqualTo(1000); processed.addAll(input); }); assertThat(processed).containsExactlyElementsOf(inputs); }
@Test public void testSimpleDataProviderWithListenerAnnotationAndInvolvingInheritance() { final String prefix = ":" + SimpleDataProviderWithListenerAnnotationSample1.class.getName() + ".testMethod"; TestNG tng = create(SimpleDataProviderWithListenerAnnotationSample1.class); tng.run(); assertThat(LocalDataProviderListener.messages) .containsExactlyElementsOf(Arrays.asList("before" + prefix, "after" + prefix)); }
@Test public void testIntList() { List<Integer> testIntList = Arrays.stream(testInts).boxed().collect(Collectors.toList()); ao.insertIntList(testIntList); assertThat(ao.fetchIntList()).containsExactlyElementsOf(testIntList); }
@Test public void ensureExecutionListenerIsInvokedOnlyOnce() { XmlSuite suite = createXmlSuite("suite"); createXmlTest(suite, "test1", TestClassSample.class, TestClassTwoSample.class); createXmlTest(suite, "test2", TestClassSample.class, TestClassTwoSample.class); TestNG testng = create(suite); testng.run(); assertThat(LocalExecutionListener.getFinish()).containsExactlyElementsOf(Collections.singletonList("finish")); assertThat(LocalExecutionListener.getStart()).containsExactlyElementsOf(Collections.singletonList("start")); }
@Test public void fluxInitialValueCanBeConsumedMultipleTimes() { // "A deferred Flux with initial values can be consumed multiple times" // given: "a composable with an initial value" Flux<String> stream = Flux.just("test", "test2", "test3") .map(v -> v) .log(); // when: "the value is retrieved" List<String> value1 = stream.collectList().block(); List<String> value2 = stream.collectList().block(); // then: "it is available" assertThat(value1).containsExactlyElementsOf(value2); }
private static void runTest(String prefix, Class<?> clazz, boolean hasListenerAnnotation) { TestNG tng = create(clazz); if (!hasListenerAnnotation) { tng.addListener(new LocalDataProviderListener()); } tng.run(); assertThat(LocalDataProviderListener.messages) .containsExactlyElementsOf(Arrays.asList("before" + prefix, "after" + prefix)); }
@Test public void scanOrDefaultOverridesGlobalDefault() { Scannable emptyScannable = key -> null; assertThat(emptyScannable.scanOrDefault(Scannable.Attr.BUFFERED, 123)).isEqualTo(123); //global 0 assertThat(emptyScannable.scanOrDefault(Scannable.Attr.CAPACITY, 123)).isEqualTo(123); //global 0 assertThat(emptyScannable.scanOrDefault(Scannable.Attr.PREFETCH, 123)).isEqualTo(123); //global 0 assertThat(emptyScannable.scanOrDefault(Scannable.Attr.LARGE_BUFFERED, 123L)).isEqualTo(123L); //global null assertThat(emptyScannable.scanOrDefault(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM, 123L)).isEqualTo(123L); //global 0 assertThat(emptyScannable.scanOrDefault(Scannable.Attr.CANCELLED, true)).isTrue(); //global false assertThat(emptyScannable.scanOrDefault(Scannable.Attr.DELAY_ERROR, true)).isTrue(); //global false assertThat(emptyScannable.scanOrDefault(Scannable.Attr.TERMINATED, true)).isTrue(); //global false assertThat(emptyScannable.scanOrDefault(Scannable.Attr.ERROR, new IllegalStateException())).isInstanceOf(IllegalStateException.class); //global null assertThat(emptyScannable.scanOrDefault(Scannable.Attr.ACTUAL, Scannable.Attr.NULL_SCAN)).isSameAs(Scannable.Attr.NULL_SCAN); //global null assertThat(emptyScannable.scanOrDefault(Scannable.Attr.PARENT, Scannable.Attr.NULL_SCAN)).isSameAs(Scannable.Attr.NULL_SCAN); // global null List<Tuple2<String, String>> tags = Collections.singletonList(Tuples.of("some", "key")); assertThat(emptyScannable.scanOrDefault(Scannable.Attr.TAGS, tags.stream())).containsExactlyElementsOf(tags); //global null assertThat(emptyScannable.scanOrDefault(Scannable.Attr.NAME, "SomeName")).isEqualTo("SomeName"); // global null }
@Test public void testInsertWithPositionalParameters() { somethingDao.insertSomething(4, "Dave", 90); List<Map<String, Object>> rows = handle.select("select * from something where something_id=?", 4).mapToMap().list(); assertThat(rows).containsExactlyElementsOf(ImmutableList.of( ImmutableMap.of("something_id", 4, "name", "Dave", "code", 90))); }
@Test public void testInsertWithDefaultParams() { somethingDao.insertWithDefaultParams("Greg", 21); List<Map<String, Object>> rows = handle.select("select * from something where something_id=?", 19).mapToMap().list(); assertThat(rows).containsExactlyElementsOf(ImmutableList.of( ImmutableMap.of("something_id", 19, "name", "Greg", "code", 21))); }
private static void runTestWithListenerViaSuiteXml(String prefix, Class<?> clazz) { XmlSuite xmlSuite = createXmlSuite("SampleSuite"); XmlTest xmlTest = createXmlTest(xmlSuite, "SampleTest"); createXmlClass(xmlTest, clazz); xmlSuite.addListener(LocalDataProviderListener.class.getName()); TestNG tng = create(xmlSuite); tng.run(); assertThat(LocalDataProviderListener.messages) .containsExactlyElementsOf(Arrays.asList("before" + prefix, "after" + prefix)); }
@Test public void testExecuteSomeStatements() { try (Handle h = dbRule.openHandle()) { h.execute("insert into something (id, name) values (?, ?)", 3, "Patrick"); List<Map<String, Object>> rs = h.select("select id, name from something").mapToMap().list(); assertThat(rs).containsExactlyElementsOf(ImmutableList.of(ImmutableMap.of("id", 3L, "name", "Patrick"))); } }
@Test public void alwaysFalseWithNSimilarToSimpleZero() { List<Integer> expected = Flux.just(1, 2, 3).repeat(0).collectList().block(); List<Integer> result = Flux.just(1, 2, 3).repeat(3, () -> false).collectList().block(); assertThat(result).containsExactlyElementsOf(expected); } }
private void assertPublished(DefaultInputFile file, Set<Integer> lines) { assertThat(new File(temp.getRoot(), "changed-lines-" + file.scannerId() + ".pb")).exists(); ScannerReportReader reader = new ScannerReportReader(temp.getRoot()); assertThat(reader.readComponentChangedLines(file.scannerId()).getLineList()).containsExactlyElementsOf(lines); }
@Test public void alwaysTrueWithNSimilarToSimpleN() { List<Integer> expected = Flux.just(1, 2, 3).repeat(3).collectList().block(); List<Integer> result = Flux.just(1, 2, 3).repeat(3, () -> true).collectList().block(); assertThat(result).containsExactlyElementsOf(expected); }
@Test(dataProvider = "dp", description ="GITHUB-1029" ) public void ensureXmlTestIsNotNull(Class<?> clazz, XmlSuite.ParallelMode mode) { XmlSuite xmlSuite = createXmlSuite("Suite"); createXmlTest(xmlSuite, "GITHUB-1029-Test", clazz); xmlSuite.setParallel(mode); Issue1029InvokedMethodListener listener = new Issue1029InvokedMethodListener(); TestNG testng = create(xmlSuite); testng.addListener(listener); testng.setThreadCount(10); testng.setDataProviderThreadCount(10); testng.run(); List<String> expected = Collections.nCopies(5, "GITHUB-1029-Test"); assertThat(listener.getBeforeInvocation()).containsExactlyElementsOf(expected); assertThat(listener.getAfterInvocation()).containsExactlyElementsOf(expected); }
@Test(dataProvider = "dp") public void testListenerInvocation(Class<?> clazz, XmlSuite.FailurePolicy policy, List<String> expected) { TestNG tng = create(clazz); ListenerForIssue1602 listener = new ListenerForIssue1602(); tng.setConfigFailurePolicy(policy); tng.setVerbose(2); tng.addListener(listener); tng.run(); assertThat(listener.getLogs()).containsExactlyElementsOf(expected); }
@Test(description = "GITHUB-1770") public void verifyDataProvider2() { InvokedMethodNameListener listener = new InvokedMethodNameListener(); XmlSuite xmlSuite = createXmlSuite("xml_suite"); XmlTest xmlTest = createXmlTest(xmlSuite, "xml_test", SampleTestFour.class); Map<String, String> parameters = Maps.newHashMap(); parameters.put("isCustom", RANDOM_VALUE); xmlTest.setParameters(parameters); TestNG testng = create(xmlSuite); testng.addListener(listener); testng.run(); assertThat(listener.getLogs("test")) .containsExactlyElementsOf(Collections.singletonList(RANDOM_VALUE)); } }
@Test public void iterableWithCombinatorHasCorrectLength() { Flux<Integer> flux1 = Flux.just(1); Flux<Integer> flux2 = Flux.just(2); Flux<Integer> flux3 = Flux.just(3); Flux<Integer> flux4 = Flux.just(4); List<Object> expected = Arrays.asList(1, 2, 3, 4); Flux<List<Object>> zipped = Flux.zip(Arrays.asList(flux1, flux2, flux3, flux4), Arrays::asList); StepVerifier.create(zipped) .consumeNextWith(t -> Assertions.assertThat(t) .containsExactlyElementsOf(expected)) .expectComplete() .verify(); }
private static void runTest(List<String> expected, Class<?> clazz, boolean skipInvocationCount) { TestNG testng = create(clazz); testng.setSkipFailedInvocationCounts(skipInvocationCount); UniversalListener listener = new UniversalListener(); testng.addListener(listener); testng.alwaysRunListeners(false); testng.run(); Assertions.assertThat(listener.getMessages()).containsExactlyElementsOf(expected); }
private static void runTest(List<String> expected, Class<?> clazz, boolean skipInvocationCount) { TestNG testng = create(clazz); testng.setSkipFailedInvocationCounts(skipInvocationCount); UniversalListener listener = new UniversalListener(); testng.addListener(listener); testng.alwaysRunListeners(true); testng.run(); Assertions.assertThat(listener.getMessages()).containsExactlyElementsOf(expected); }