public static void assertSkippedOutputBufferCount(String name, DecoderCounters counters, int expected) { counters.ensureUpdated(); int actual = counters.skippedOutputBufferCount; assertWithMessage( "Codec(" + name + ") skipped " + actual + " buffers. Expected " + expected + ".") .that(actual) .isEqualTo(expected); }
/** Asserts that there is no cache content for the given {@code uriStrings}. */ public static void assertDataNotCached(Cache cache, String... uriStrings) { for (String uriString : uriStrings) { assertWithMessage("There is cached data for '" + uriString + "',") .that(cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty()) .isTrue(); } }
public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Exception { TestLogHandler listenerLoggerHandler = new TestLogHandler(); Logger exceptionLogger = Logger.getLogger(AbstractFuture.class.getName()); exceptionLogger.addHandler(listenerLoggerHandler); try { doTestSuccessfulAsList_resultCancelledRacingInputDone(); assertWithMessage("Nothing should be logged") .that(listenerLoggerHandler.getStoredLogRecords()) .isEmpty(); } finally { exceptionLogger.removeHandler(listenerLoggerHandler); } }
public void testMultipleQuantile() { ImmutableSet<Integer> indexes = ImmutableSet.of(50, 90, 99); Map<Integer, Double> referenceQuantiles = REFERENCE_ALGORITHM.multipleQuantiles(indexes, 100, dataset.clone()); assertThat(referenceQuantiles.keySet()).isEqualTo(indexes); for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) { Map<Integer, Double> quantiles = algorithm.multipleQuantiles(indexes, 100, dataset.clone()); assertWithMessage("Wrong keys from " + algorithm).that(quantiles.keySet()).isEqualTo(indexes); for (int i : indexes) { assertWithMessage("Mismatch between %s and %s at %s", algorithm, REFERENCE_ALGORITHM, i) .that(quantiles.get(i)) .isWithin(ALLOWED_ERROR) .of(referenceQuantiles.get(i)); } } } }
public void test() { assertUsedAsRule(); isUsedWithoutCallingTest = false; tester.test(); assertThat(regressionTests).isNotEmpty(); int i = 1; for (Entry<Key, String> entry : regressionTests.entrySet()) { assert_() .withMessage( "Unexpected digest for regression test [" + i + "]: with key: " + entry.getKey()) .that(sha256.getStringDigest(entry.getKey())).isEqualTo(entry.getValue()); i++; } }
/** Asserts that there is no cache content for the given {@code uriStrings}. */ public static void assertDataNotCached(Cache cache, String... uriStrings) { for (String uriString : uriStrings) { assertWithMessage("There is cached data for '" + uriString + "'") .that(cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString)))) .isEmpty(); } }
public static void assertSkippedOutputBufferCount(String name, DecoderCounters counters, int expected) { counters.ensureUpdated(); int actual = counters.skippedOutputBufferCount; assertWithMessage( "Codec(" + name + ") skipped " + actual + " buffers. Expected " + expected + ".") .that(actual) .isEqualTo(expected); }
@Override public void testNulls() throws Exception { try { super.testNulls(); } catch (AssertionFailedError e) { assertWithMessage("Method did not throw null pointer OR element not in graph exception.") .that(e) .hasCauseThat() .hasMessageThat() .contains(ERROR_ELEMENT_NOT_IN_GRAPH); } }
private void assertNullCacheSpan(File parent, String key, long offset, long lastAccessTimestamp) { File cacheFile = SimpleCacheSpan.getCacheFile(parent, index.assignIdForKey(key), offset, lastAccessTimestamp); CacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index); assertWithMessage(cacheFile.toString()).that(cacheSpan).isNull(); }
/** Asserts that there is no cache content for the given {@code uriStrings}. */ public static void assertDataNotCached(Cache cache, String... uriStrings) { for (String uriString : uriStrings) { assertWithMessage("There is cached data for '" + uriString + "',") .that(cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty()) .isTrue(); } }
public void testNoNullValues() { for (StandardSystemProperty property : StandardSystemProperty.values()) { // Even though the contract in System.getProperties() specifies that a value will exist for // all of the listed keys, for some reason the "java.compiler" key returns null in some JVMs. if (property == JAVA_COMPILER) { continue; } // Removed in Java 9: // https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-2C896CA8-927C-4381-A737-B1D81D964B7B if (property == JAVA_EXT_DIRS) { continue; } assertWithMessage(property.toString()).that(property.value()).isNotNull(); } } }
private void assertUnderline(Spannable spannable, boolean isUnderline) { UnderlineSpan[] underlineSpans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class); assertWithMessage(isUnderline ? "must be underlined" : "must not be underlined") .that(underlineSpans) .hasLength(isUnderline ? 1 : 0); }
private void assertStrikethrough(Spannable spannable, boolean isStrikethrough) { StrikethroughSpan[] striketroughSpans = spannable.getSpans(0, spannable.length(), StrikethroughSpan.class); assertWithMessage(isStrikethrough ? "must be strikethrough" : "must not be strikethrough") .that(striketroughSpans) .hasLength(isStrikethrough ? 1 : 0); }
@Test public void testInheritStyle() { style.inherit(createAncestorStyle()); assertWithMessage("id must not be inherited").that(style.getId()).isNull(); assertThat(style.isUnderline()).isTrue(); assertThat(style.isLinethrough()).isTrue(); assertThat(style.getStyle()).isEqualTo(STYLE_BOLD_ITALIC); assertThat(style.getFontFamily()).isEqualTo(FONT_FAMILY); assertThat(style.getFontColor()).isEqualTo(WHITE); assertWithMessage("do not inherit backgroundColor").that(style.hasBackgroundColor()).isFalse(); }
public void testSingleQuantile_median() { double referenceValue = REFERENCE_ALGORITHM.singleQuantile(1, 2, dataset.clone()); for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) { assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM) .that(algorithm.singleQuantile(1, 2, dataset.clone())) .isWithin(ALLOWED_ERROR) .of(referenceValue); } }
public void testSingleQuantile_percentile99() { double referenceValue = REFERENCE_ALGORITHM.singleQuantile(99, 100, dataset.clone()); for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) { assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM) .that(algorithm.singleQuantile(99, 100, dataset.clone())) .isWithin(ALLOWED_ERROR) .of(referenceValue); } }
@Test public void testChainStyle() { style.chain(createAncestorStyle()); assertWithMessage("id must not be inherited").that(style.getId()).isNull(); assertThat(style.isUnderline()).isTrue(); assertThat(style.isLinethrough()).isTrue(); assertThat(style.getStyle()).isEqualTo(STYLE_BOLD_ITALIC); assertThat(style.getFontFamily()).isEqualTo(FONT_FAMILY); assertThat(style.getFontColor()).isEqualTo(FOREGROUND_COLOR); // do inherit backgroundColor when chaining assertWithMessage("do not inherit backgroundColor when chaining") .that(style.getBackgroundColor()).isEqualTo(BACKGROUND_COLOR); }
/** Non-Error exceptions are never logged. */ @SuppressWarnings("unchecked") public void testSuccessfulAsList_logging_exception() throws Exception { assertEquals( newArrayList((Object) null), getDone(successfulAsList(immediateFailedFuture(new MyException())))); assertWithMessage("Nothing should be logged") .that(aggregateFutureLogHandler.getStoredLogRecords()) .isEmpty(); // Not even if there are a bunch of failures. assertEquals( newArrayList(null, null, null), getDone( successfulAsList( immediateFailedFuture(new MyException()), immediateFailedFuture(new MyException()), immediateFailedFuture(new MyException())))); assertWithMessage("Nothing should be logged") .that(aggregateFutureLogHandler.getStoredLogRecords()) .isEmpty(); }
@Test public void testNoUnderline() throws IOException, SubtitleDecoderException { TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE); assertThat(subtitle.getEventTimeCount()).isEqualTo(4); TtmlNode root = subtitle.getRoot(); TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0); TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0); TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style; assertWithMessage("noUnderline from inline attribute expected") .that(style.isUnderline()) .isFalse(); }
@Test public void testNoLinethrough() throws IOException, SubtitleDecoderException { TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE); assertThat(subtitle.getEventTimeCount()).isEqualTo(4); TtmlNode root = subtitle.getRoot(); TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0); TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 1); TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style; assertWithMessage("noLineThrough from inline attribute expected in second pNode") .that(style.isLinethrough()) .isFalse(); }