public static void assertEquals(List<String> filters) { List<String> expected = ordered.stream() .map(SecurityFilters::name) .collect(Collectors.toList()); assertThat(filters).isEqualTo(expected); } }
private void assertDatabaseContainsExactly(List<User> expectedUsers) { assertThat(db.select(SELECT_USERS)).isEqualTo( expectedUsers.stream().map(User::toMap).collect(Collectors.toList()) ); }
@Test public void getWorkerUuids_returns_ordered_list_of_uuids_of_worker_from_CeWorkerFactory_instance() { List<String> workerUuids = underTest.getWorkerUuids(); assertThat(workerUuids).isEqualTo(WORKERS.stream().map(CeWorker::getUUID).sorted().collect(Collectors.toList())); // ImmutableSet can not be serialized assertThat(workerUuids).isNotInstanceOf(ImmutableSet.class); }
@Test public void shutdownNow() { List<Runnable> result = executor.shutdownNow(); verify(delegate).shutdownNow(); assertThat(result).isEqualTo(delegate.shutdownNow()).isNotNull(); }
@Test @SuppressWarnings("unchecked") public void invokeAll() throws Exception { List<Future<Object>> exectedResult = Arrays.asList(expectedFutureObject); List<Callable<Object>> wrappedCallables = Arrays.asList(wrappedCallable); when(delegate.invokeAll(wrappedCallables)).thenReturn(exectedResult); List<Future<Object>> result = executor.invokeAll(Arrays.asList(callable)); verify(delegate).invokeAll(wrappedCallables); assertThat(result).isEqualTo(exectedResult); }
@Test public void testReadStream() throws IOException { byte[] data = adapter.encode(allTypes); InputStream stream = new ByteArrayInputStream(data); AllTypes parsed = adapter.decode(stream); assertThat(parsed).isEqualTo(allTypes); assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE); assertThat(allTypes.ext_rep_bool).isEqualTo(list(true)); assertThat(allTypes.ext_pack_bool).isEqualTo(list(true)); }
@Test @SuppressWarnings("unchecked") public void invokeAllTimeout() throws Exception { List<Future<Object>> exectedResult = Arrays.asList(expectedFutureObject); List<Callable<Object>> wrappedCallables = Arrays.asList(wrappedCallable); when(delegate.invokeAll(wrappedCallables, 1, TimeUnit.SECONDS)).thenReturn( exectedResult); List<Future<Object>> result = executor.invokeAll(Arrays.asList(callable), 1, TimeUnit.SECONDS); verify(delegate).invokeAll(wrappedCallables, 1, TimeUnit.SECONDS); assertThat(result).isEqualTo(exectedResult); }
@Test public void testReadBytes() throws IOException { byte[] data = adapter.encode(allTypes); AllTypes parsed = adapter.decode(data); assertThat(parsed).isEqualTo(allTypes); assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE); assertThat(allTypes.ext_rep_bool).isEqualTo(list(true)); assertThat(allTypes.ext_pack_bool).isEqualTo(list(true)); }
@Test public void testReadSource() throws IOException { byte[] data = adapter.encode(allTypes); Buffer input = new Buffer().write(data); AllTypes parsed = adapter.decode(input); assertThat(parsed).isEqualTo(allTypes); assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE); assertThat(allTypes.ext_rep_bool).isEqualTo(list(true)); assertThat(allTypes.ext_pack_bool).isEqualTo(list(true)); }
@Test public void testReadFromSlowSource() throws IOException { byte[] data = adapter.encode(allTypes); Source input = new SlowSource(new Buffer().write(data)); AllTypes parsed = adapter.decode(Okio.buffer(input)); assertThat(parsed).isEqualTo(allTypes); assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE); assertThat(allTypes.ext_rep_bool).isEqualTo(list(true)); assertThat(allTypes.ext_pack_bool).isEqualTo(list(true)); }
@Test public void testReadLongMessages() throws IOException { AllTypes allTypes = createAllTypes(50); byte[] data = adapter.encode(allTypes); AllTypes parsed = adapter.decode(data); assertThat(parsed).isEqualTo(allTypes); assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE); assertThat(allTypes.ext_rep_bool).isEqualTo(list(true, 50)); assertThat(allTypes.ext_pack_bool).isEqualTo(list(true, 50)); }
@Test public void test_order() { Collection<Section> sections = asList( newSection("end2"), newSection("bar"), newSection("end1"), newSection("foo")); List<String> ordered = SystemInfoUtils.order(sections, "foo", "bar").stream() .map(Section::getName) .collect(Collectors.toList()); assertThat(ordered).isEqualTo(asList("foo", "bar", "end1", "end2")); }
@Test public void should_persist_without_significant_code_from_cache_if_possible() { List<String> lineHashes = Lists.newArrayList("line1", "line2", "line3"); sourceLinesHashCache.computeIfAbsent(file, c -> lineHashes); when(dbLineHashVersion.hasLineHashesWithSignificantCode(file)).thenReturn(false); when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.empty()); LineHashesComputer hashesComputer = underTest.getLineHashesComputerToPersist(file); assertThat(hashesComputer).isInstanceOf(CachedLineHashesComputer.class); assertThat(hashesComputer.getResult()).isEqualTo(lineHashes); }
@Test public void get_returns_value_if_cached() { List<String> list = Collections.singletonList("hash1"); Component component = createComponent(1); underTest.computeIfAbsent(component, c -> list); assertThat(underTest.get(component)).isEqualTo(list); }
@Test public void should_not_crash_on_null_metrics_from_faulty_plugins() { Metrics faultyMetrics = () -> null; Metrics okMetrics = new FakeMetrics(); List<Metric> metrics = metrics(okMetrics, faultyMetrics); metrics.removeAll(SENSOR_METRICS_WITHOUT_METRIC_PLUGIN); assertThat(metrics).isEqualTo(okMetrics.getMetrics()); }
@Test public void should_persist_with_significant_code_from_cache_if_possible() { List<String> lineHashes = Lists.newArrayList("line1", "line2", "line3"); LineRange[] lineRanges = {new LineRange(0, 1), null, new LineRange(1, 5)}; sourceLinesHashCache.computeIfAbsent(file, c -> lineHashes); when(dbLineHashVersion.hasLineHashesWithSignificantCode(file)).thenReturn(true); when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.of(lineRanges)); LineHashesComputer hashesComputer = underTest.getLineHashesComputerToPersist(file); assertThat(hashesComputer).isInstanceOf(CachedLineHashesComputer.class); assertThat(hashesComputer.getResult()).isEqualTo(lineHashes); }
@Test public void handleWhenNotOAuth2AuthenticatedThenStatus403() { Authentication token = new TestingAuthenticationToken("user", "pass"); ServerWebExchange exchange = mock(ServerWebExchange.class); when(exchange.getPrincipal()).thenReturn(Mono.just(token)); when(exchange.getResponse()).thenReturn(new MockServerHttpResponse()); this.accessDeniedHandler.handle(exchange, null).block(); assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); assertThat(exchange.getResponse().getHeaders().get("WWW-Authenticate")).isEqualTo( Arrays.asList("Bearer")); }
@Test public void handleWhenNotOAuth2AuthenticatedAndRealmSetThenStatus403AndAuthHeaderWithRealm() { Authentication token = new TestingAuthenticationToken("user", "pass"); ServerWebExchange exchange = mock(ServerWebExchange.class); when(exchange.getPrincipal()).thenReturn(Mono.just(token)); when(exchange.getResponse()).thenReturn(new MockServerHttpResponse()); this.accessDeniedHandler.setRealmName("test"); this.accessDeniedHandler.handle(exchange, null).block(); assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); assertThat(exchange.getResponse().getHeaders().get("WWW-Authenticate")).isEqualTo( Arrays.asList("Bearer realm=\"test\"")); }
private static void verifyLinesHashes(LineHashesWithKeyDtoHandler handler, ComponentDto file, FileSourceDto fileSource) { LineHashesWithUuidDto dto = handler.getByUuid(file.uuid()).get(); assertThat(dto.getPath()).isEqualTo(file.path()); assertThat(dto.getRawLineHashes()).isEqualTo(fileSource.getRawLineHashes()); assertThat(dto.getLineHashes()).isEqualTo(fileSource.getLineHashes()); }
@Test public void migration_should_be_reentrant() throws SQLException { for (int i = 0; i < 10; i++) { insertWebhookDelivery(randomAlphanumeric(40),null, randomAlphanumeric(40)); insertCeActivity(randomAlphanumeric(40), randomAlphanumeric(40)); } underTest.execute(); List<Map<String, Object>> firstExecutionResult = selectAllWebhookDeliveries(); underTest.execute(); assertThat(selectAllWebhookDeliveries()).isEqualTo(firstExecutionResult); }