@Test public void testConstructorFromByteArray() { final RowKey rowKey = new RowKey(buildRowKeyArray()); assertEquals(STAT_TYPE_ID, rowKey.getTypeId()); Assertions.assertThat(ROLL_UP_BIT_MASK).isEqualTo(rowKey.getRollUpBitMask()); Assertions.assertThat(PARTIAL_TIMESTAMP).isEqualTo(rowKey.getPartialTimestamp()); final List<RowKeyTagValue> tagValuePairs = rowKey.getTagValuePairs(); assertEquals(3, tagValuePairs.size()); assertEquals(TAG_2, tagValuePairs.get(0).getTag()); assertEquals(VALUE_2, tagValuePairs.get(0).getValue()); assertEquals(TAG_1, tagValuePairs.get(1).getTag()); assertEquals(VALUE_1, tagValuePairs.get(1).getValue()); assertEquals(TAG_3, tagValuePairs.get(2).getTag()); assertEquals(VALUE_3, tagValuePairs.get(2).getValue()); }
@Test public void call() throws Exception { // given HelloWorldWork work1 = new HelloWorldWork("work1", WorkStatus.COMPLETED); HelloWorldWork work2 = new HelloWorldWork("work2", WorkStatus.FAILED); ParallelFlowExecutor parallelFlowExecutor = new ParallelFlowExecutor(); // when List<WorkReport> workReports = parallelFlowExecutor.executeInParallel(Arrays.asList(work1, work2)); // then Assertions.assertThat(workReports).hasSize(2); Assertions.assertThat(work1.isExecuted()).isTrue(); Assertions.assertThat(work2.isExecuted()).isTrue(); }
@Test public void deleteAsyncCollection() throws Exception { TestLongEntity[] entities = fixture.get(3); ofy().save().entities(entities).now(); List<TestLongEntity> listBeforeDelete = ofy().load().type(TestLongEntity.class).list(); Assertions.assertThat(listBeforeDelete).hasSize(3); repository.deleteAsync( Arrays.asList(entities[0], entities[1]) ).run(); List<TestLongEntity> listAfterDelete = ofy().load().type(TestLongEntity.class).list(); Assertions.assertThat(listAfterDelete).hasSize(1); Assertions.assertThat(listAfterDelete).containsExactly(entities[2]); }
@Then("^validate record is present in SF \"([^\"]*)\"") public void validateIntegration(String record) throws TwitterException { Assertions.assertThat(getSalesforceContact(salesforce, accountsDirectory.getAccount(RestConstants.getInstance().getSYNDESIS_TALKY_ACCOUNT()) .get().getProperty("screenName")).isPresent()).isEqualTo(false); log.info("Waiting until a contact appears in salesforce..."); final long start = System.currentTimeMillis(); final boolean contactCreated = TestUtils.waitForEvent(contact -> contact.isPresent(), () -> getSalesforceContact(salesforce, accountsDirectory.getAccount(RestConstants.getInstance().getSYNDESIS_TALKY_ACCOUNT()).get().getProperty("screenName")), TimeUnit.MINUTES, 2, TimeUnit.SECONDS, 5); Assertions.assertThat(contactCreated).as("Contact has appeard in salesforce").isEqualTo(true); log.info("Contact appeared in salesforce. It took {}s to create contact.", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start)); final Contact createdContact = getSalesforceContact(salesforce, accountsDirectory.getAccount(RestConstants.getInstance().getSYNDESIS_TALKY_ACCOUNT()).get().getProperty("screenName")).get(); Assertions.assertThat(createdContact.getDescription()).startsWith(record); Assertions.assertThat(createdContact.getFirstName()).isNotEmpty(); Assertions.assertThat(createdContact.getLastname()).isNotEmpty(); log.info("Twitter to salesforce integration test finished."); }
@Test public void visit_shouldVisitAllItems() throws Exception { //given List<Object> list = new ArrayList<>(); OutputContainer.CellVisitor visitor = new OutputContainer.CellVisitor() { @Override public void visit(Object item) { list.add(item); } }; container.addItem(Integer.MIN_VALUE, 0); container.addItem(Boolean.TRUE, 1); //when container.visit(visitor); //then Assertions.assertThat(list).isNotEmpty(); Assertions.assertThat(list.size()).isEqualTo(2); Assertions.assertThat(list.get(1)).isEqualTo(true); }
@Test public void rxSingleIntFallback() { server.enqueue(new MockResponse().setResponseCode(500)); TestInterface api = target(); Single<Integer> single = api.intSingle(); assertThat(single).isNotNull(); assertThat(server.getRequestCount()).isEqualTo(0); TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>(); single.subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); Assertions.assertThat(testSubscriber.getOnNextEvents().get(0)).isEqualTo(new Integer(0)); }
@Test public void discoveryClientWithWrongUrlShouldUseServiceInstanceInfo() { String serviceId = "serviceId"; URI uri = URI.create("http://service-instance-uri"); EurekaServiceInstance serviceInstanceMock = Mockito.mock(EurekaServiceInstance.class); Mockito.when(serviceInstanceMock.getUri()).thenReturn(uri); Mockito.when(serviceInstanceMock.getServiceId()).thenReturn(serviceId); Mockito.when(discoveryClient.getServices()).thenReturn(Lists.newArrayList("serviceId")); Mockito.when(discoveryClient.getInstances("serviceId")).thenReturn(Lists.newArrayList(serviceInstanceMock)); Mockito.when(serviceInstanceMock.getMetadata()) .thenReturn(Maps.newHashMap(CereebroMetadata.KEY_SNITCH_URI, "")); DiscoveryClientSnitchRegistry registry = new DiscoveryClientSnitchRegistry(discoveryClient, objectMapper); Assertions.assertThat(registry.getAll()).hasSize(1); Snitch snitch = registry.getAll().get(0); Assertions.assertThat(snitch).isInstanceOf(ServiceInstanceSnitch.class); Assertions.assertThat(snitch.getUri()).isEqualTo(uri); Component component = Component.of(serviceId, ComponentType.HTTP_APPLICATION); SystemFragment expected = SystemFragment.of(ComponentRelationships.of(component, new HashSet<>())); Assertions.assertThat(snitch.snitch()).isEqualTo(expected); }
public static void assertLogsContainsOrNot(Collection<Pod> pods, String[] shouldFinds, String[] shouldNotFinds) throws IOException { Pattern patterns[] = new Pattern[shouldFinds.length + shouldNotFinds.length]; for (int i = 0; i < shouldFinds.length; ++i) { patterns[i] = Pattern.compile(shouldFinds[i]); } for (int i = 0; i < shouldNotFinds.length; ++i) { patterns[shouldFinds.length + i] = Pattern.compile(shouldNotFinds[i]); } boolean found[] = findPatternsInLogs(pods, patterns); for (int i = 0; i < patterns.length; ++i) { if (i < shouldFinds.length) { Assertions.assertThat(found[i]).as("Didn't find pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(true); } else { Assertions.assertThat(found[i]).as("Found pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(false); } } }
@Test public void should_not_return_merged_test_selections_if_test_selection_has_different_class() { // given final TestSelection testSelectionNew = new TestSelection(TestExecutionPlannerLoaderTest.class.getName(), "new"); final TestSelection testSelectionChanged = new TestSelection(TestSelectorTest.class.getName(), "changed"); final Set<Class<?>> classes = new LinkedHashSet<>(asList(TestExecutionPlannerLoaderTest.class, TestSelectorTest.class)); TestExecutionPlannerLoader testExecutionPlannerLoader = prepareLoader(classes); final DummyTestSelector testSelector = new DummyTestSelector(ConfigurationLoader.load(tmpFolder.getRoot()), testExecutionPlannerLoader, new File(".")); // when final Collection<TestSelection> testSelections = testSelector.filterMergeAndOrderTestSelection(asList(testSelectionNew, testSelectionChanged), asList("new", "changed")); // then Assertions.assertThat(testSelections) .hasSize(2) .flatExtracting("types").containsExactly("new", "changed"); }
@Test public void handleMessage_secondSentMessageHasSessionId() throws Exception { //given String expectedSessionId = message.getHeader().getSession(); //when commMsgHandler.handle(message); //then Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void create() { Component a = Component.of("a", "a"); Component b = Component.of("b", "b"); Component c = Component.of("c", "c"); ComponentRelationships aRels = ComponentRelationships.builder().component(a).addDependency(Dependency.on(b)) .build(); ComponentRelationships bRels = ComponentRelationships.builder().component(b).addDependency(Dependency.on(c)) .build(); ComponentRelationships cRels = ComponentRelationships.builder().component(c).build(); LinkedHashSet<ComponentRelationships> set = new LinkedHashSet<>(); set.add(aRels); set.add(bRels); set.add(cRels); System system = System.of("sys", set); DependencyWheel result = DependencyWheel.of(system); // @formatter:off DependencyWheel expected = DependencyWheel.builder() .name("a") .matrixLine(Arrays.asList(0, 1, 0)) .name("b") .matrixLine(Arrays.asList(0, 0, 1)) .name("c") .matrixLine(Arrays.asList(0, 0, 0)) .build(); // @formatter:on Assertions.assertThat(result).isEqualTo(expected); }
@Test public void setBoundsWithTwoDoubleParams_hasBoundsValuesAndHasAutoRangeIsFalse() { //when YAxis yAxis = new YAxis(); yAxis.setBound(1, 2); //then Assertions.assertThat(yAxis.getAutoRange()).isEqualTo(false); Assertions.assertThat(yAxis.getLowerBound()).isEqualTo(1); Assertions.assertThat(yAxis.getUpperBound()).isEqualTo(2); }
@Test public void testSchemeAssets() throws Exception { String uri = "assets://folder/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.ASSETS; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void serializeStickyOfTreeMap_resultJsonHasSticky() throws IOException { //when treeMap.setSticky(true); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("sticky")).isTrue(); Assertions.assertThat(actualObj.get("sticky").asBoolean()).isTrue(); }
@Test public void createPointsByEmptyConstructor_hasSizeAndShapeIsNotNull() { //when Points points = new Points(); //then Assertions.assertThat(points.getSize()).isNotNull(); Assertions.assertThat(points.getShape()).isNotNull(); }
@Nonnull public MethodSpecAssert hasNoJavaDoc() { isNotNull(); final CodeBlock actual = this.actual.javadoc; Assertions.assertThat(actual) .overridingErrorMessage("Expected javadoc to be empty, but was <%s>", actual) .isEqualTo(CodeBlock.builder().build()); return this; }
@Test public void handleMessage_setShellOptions() throws Exception { //given initMessageData(message); //when commHandler.handle(message); //then Assertions.assertThat(kernel.isSetShellOptions()).isTrue(); }
@Test public void orderShouldCreateCorrectBeverageForGivenCode() { Assertions.assertThat(Coffee.order("A")).isEqualTo(new Coffee.Akkaccino()); Assertions.assertThat(Coffee.order("a")).isEqualTo(new Coffee.Akkaccino()); Assertions.assertThat(Coffee.order("C")).isEqualTo(new Coffee.CaffeJava()); Assertions.assertThat(Coffee.order("c")).isEqualTo(new Coffee.CaffeJava()); Assertions.assertThat(Coffee.order("M")).isEqualTo(new Coffee.MochaPlay()); Assertions.assertThat(Coffee.order("m")).isEqualTo(new Coffee.MochaPlay()); }
@Test public void finishThrowExceptionIfNoLogContext() throws Exception { try { SmartLog.finish(); } catch (Exception e) { Assertions.assertThat(e).hasMessage("Loggable context is absent"); } }
@Test public void discoveryClientWithEmptyInstance() { Mockito.when(discoveryClient.getServices()).thenReturn(Lists.newArrayList("serviceId")); Mockito.when(discoveryClient.getInstances("serviceId")).thenReturn(Collections.emptyList()); DiscoveryClientSnitchRegistry snitchR = new DiscoveryClientSnitchRegistry(discoveryClient, objectMapper); Assertions.assertThat(snitchR.getAll()).isEmpty(); }
@Test public void testSchemeFile() throws Exception { String uri = "file://path/on/the/device/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.FILE; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void should_return_false_for_class_containing_no_category_when_no_category_set() { // given CategorizedConfiguration categorizedConfig = prepareConfig(); CategoriesParser categoriesParser = new CategoriesParser(categorizedConfig); // when boolean hasCorrectCategories = categoriesParser.hasCorrectCategories(NonCategorizedClass.class); // then Assertions.assertThat(hasCorrectCategories).isFalse(); }
@Test public void getNamespaceClientByCurrentSessionId_returnNamespaceClient() { //when NamespaceClient curNamespaceClient = NamespaceClient.getBeaker(); //then Assertions.assertThat(curNamespaceClient).isNotNull(); Assertions.assertThat(curNamespaceClient).isEqualTo(namespaceClient); }
@Test public void serializeBufferedImage_resultJsonHasType() throws IOException { //when JsonNode actualObj = helper.serializeObject(bufferedImage); //then Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("ImageIcon"); }
public static void assertLogsContains(Collection<Pod> pods, Pattern... patterns) throws IOException { boolean found[] = findPatternsInLogs(pods, patterns); for (int i = 0; i < patterns.length; ++i) { Assertions.assertThat(found[i]).as("Didn't find pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + " logs").isEqualTo(true); } }
@Test public void parsePlotWithLegendPositionScript_returnPlotObjectWithLegendPosition() { //when Object result = parseClassFromScript("def pp = new Plot(legendPosition: LegendPosition.TOP)"); //then Assertions.assertThat(result instanceof Plot).isTrue(); Plot plot = (Plot) result; Assertions.assertThat(plot.getLegendPosition()).isEqualTo(LegendPosition.TOP); }
/** * Check that a property has specific content * * @param contentQName Which property to check * @param expected String-representation of the expected content * @return The created node assertion object */ public NodeAssert hasContent(final QName contentQName, final String expected) { isNotNull(); exists(); final ContentReader reader = contentService.getReader(actual, contentQName); if (reader != null) { Assertions.assertThat(reader.getContentString()).as("Content should be equal").isEqualTo(expected); } else { failWithMessage("Node <%s> should have content ", actual); } return this; }
@Test public void handleMessage_shouldSendShellSocketMessage() throws Exception { //given CommKernelControlGetDefaultShellHandlerTest.initMessageData(message); //when commHandler.handle(message); //then Assertions.assertThat(kernelTest.getPublishedMessages()).isNotEmpty(); }
@Test public void serializeColumnName_resultJsonHasColumnName() throws IOException { //given UniqueEntriesHighlighter highlighter = (UniqueEntriesHighlighter) TableDisplayCellHighlighter.getUniqueEntriesHighlighter("a"); //when JsonNode actualObj = serializeHighliter(highlighter); //then Assertions.assertThat(actualObj.has("colName")).isTrue(); Assertions.assertThat(actualObj.get("colName").asText()).isEqualTo("a"); }
@Test public void serializeColumns_resultJsonHasColumns() throws IOException { int num = layoutManager.getColumns(); //when JsonNode actualObj = helper.serializeObject(layoutManager); //then Assertions.assertThat(actualObj.has("columns")).isTrue(); Assertions.assertThat(actualObj.get("columns").asInt()).isEqualTo(num); }
@Test public void createLineByEmptyConstructor_lineHasStyleIsNull() { //when Line line = new Line(); //then Assertions.assertThat(line.getStyle()).isNull(); }
@Test public void handle_sentMessageHasLanguageInfo() throws Exception { //when handler.handle(message); //then Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("language_info")).isNotNull(); }
@Nonnull public MethodSpecAssert hasNoParameter() { isNotNull(); final List<ParameterSpec> actual = this.actual.parameters; Assertions.assertThat(actual) .overridingErrorMessage("Expected parameters to be empty, but was <%s>", actual) .isEmpty(); return this; }
@Test public void testComputeImageSampleSize_fitInside() throws Exception { final ViewScaleType scaleType = ViewScaleType.FIT_INSIDE; int result; ImageSize srcSize = new ImageSize(300, 100); ImageSize targetSize = new ImageSize(30, 10); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false); Assertions.assertThat(result).isEqualTo(10); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true); Assertions.assertThat(result).isEqualTo(8); srcSize = new ImageSize(300, 100); targetSize = new ImageSize(200, 200); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false); Assertions.assertThat(result).isEqualTo(1); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true); Assertions.assertThat(result).isEqualTo(1); srcSize = new ImageSize(300, 100); targetSize = new ImageSize(55, 40); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false); Assertions.assertThat(result).isEqualTo(5); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true); Assertions.assertThat(result).isEqualTo(4); srcSize = new ImageSize(300, 100); targetSize = new ImageSize(30, 40); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false); Assertions.assertThat(result).isEqualTo(10); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true); Assertions.assertThat(result).isEqualTo(8); srcSize = new ImageSize(5000, 70); targetSize = new ImageSize(2000, 30); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, false); Assertions.assertThat(result).isEqualTo(3); result = ImageSizeUtils.computeImageSampleSize(srcSize, targetSize, scaleType, true); Assertions.assertThat(result).isEqualTo(4); }
@Test public void requestHeaders_withEmptyArray() { RequestHeaders requestHeaders = getDynamic("header1", 0); HttpHeaders httpHeaders = requestHeaders.encode(new Object[]{new Integer[]{}}); Assertions.assertThat(httpHeaders) .isEmpty(); }
@Test public void runtimeExceptionShouldBeTranslatedToError() { Snitch snitchMock = Mockito.mock(Snitch.class); URI uri = URI.create("http://nope"); String message = "nope"; Mockito.when(snitchMock.getUri()).thenReturn(uri); RuntimeException exceptionMock = Mockito.mock(RuntimeException.class); Mockito.when(exceptionMock.getMessage()).thenReturn(message); Mockito.when(snitchMock.snitch()).thenThrow(exceptionMock); System actual = resolver.resolve(SYSTEM_NAME, StaticSnitchRegistry.of(snitchMock)); ResolutionError error = ResolutionError.of(uri, "Could not access or process Snitch"); System expected = System.of(SYSTEM_NAME, new HashSet<>(), new HashSet<>(Arrays.asList(error))); Assertions.assertThat(actual).isEqualTo(expected); }
@Test public void test() { Assertions.assertThat(builder).isNotNull(); Assertions.assertThat(context.getRoutes().size()).isEqualTo(1); Assertions.assertThat(context.getEndpoint("direct:start")).isNotNull(); Assertions.assertThat(context.getEndpoint("mock:result")).isNotNull(); }
public ProjectAssert doesNotContainDirectory(String dirName) throws IOException { List<Path> reports = Files .walk(actual.getRoot()) .filter(path -> path.toFile().getName().equals(dirName)) .collect(Collectors.toList()); Assertions.assertThat(reports).as("There should be no directory %s present", dirName).isEmpty(); return this; }
@Test public void serializeDecimalStringFormat_resultJsonHasDecimalType() throws IOException { //given DecimalStringFormat decimalStringFormat = new DecimalStringFormat(); //when JsonNode actualObj = serializeDecimalStringFormat(decimalStringFormat); //then Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("decimal"); }
@Test public void createLegendPositionWithLeftPositionParam_hasLeftPosition() { //when LegendPosition legendPosition = new LegendPosition(LegendPosition.Position.LEFT); //then Assertions.assertThat(legendPosition.getPosition()).isEqualTo(LegendPosition.Position.LEFT); }