android.test.MoreAsserts Java Examples

The following examples show how to use android.test.MoreAsserts. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FakeTrackOutput.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
public void assertEquals(FakeTrackOutput expected) {
  Assert.assertEquals(expected.format, format);
  Assert.assertEquals(expected.sampleTimesUs.size(), sampleTimesUs.size());
  MoreAsserts.assertEquals(expected.sampleData, sampleData);
  for (int i = 0; i < sampleTimesUs.size(); i++) {
    Assert.assertEquals(expected.sampleTimesUs.get(i), sampleTimesUs.get(i));
    Assert.assertEquals(expected.sampleFlags.get(i), sampleFlags.get(i));
    Assert.assertEquals(expected.sampleStartOffsets.get(i), sampleStartOffsets.get(i));
    Assert.assertEquals(expected.sampleEndOffsets.get(i), sampleEndOffsets.get(i));
    if (expected.sampleEncryptionKeys.get(i) == null) {
      Assert.assertNull(sampleEncryptionKeys.get(i));
    } else {
      MoreAsserts.assertEquals(expected.sampleEncryptionKeys.get(i), sampleEncryptionKeys.get(i));
    }
  }
}
 
Example #2
Source File: SpannableTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@MediumTest
public void testGetSpans() {
    Spannable spannable = newSpannableWithText("abcdef");
    Object emptySpan = new Object();
    spannable.setSpan(emptySpan, 1, 1, 0);
    Object unemptySpan = new Object();
    spannable.setSpan(unemptySpan, 1, 2, 0);

    Object[] spans;

    // Empty spans are included when they merely abut the query region
    // but other spans are not, unless the query region is empty, in
    // in which case any abutting spans are returned.
    spans = spannable.getSpans(0, 1, Object.class);
    MoreAsserts.assertEquals(new Object[]{emptySpan}, spans);
    spans = spannable.getSpans(0, 2, Object.class);
    MoreAsserts.assertEquals(new Object[]{emptySpan, unemptySpan}, spans);
    spans = spannable.getSpans(1, 2, Object.class);
    MoreAsserts.assertEquals(new Object[]{emptySpan, unemptySpan}, spans);
    spans = spannable.getSpans(2, 2, Object.class);
    MoreAsserts.assertEquals(new Object[]{unemptySpan}, spans);
}
 
Example #3
Source File: FakeTrackOutput.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void assertSample(int index, byte[] data, long timeUs, int flags, byte[] encryptionKey) {
  byte[] actualData = getSampleData(index);
  MoreAsserts.assertEquals(data, actualData);
  Assert.assertEquals(timeUs, (long) sampleTimesUs.get(index));
  Assert.assertEquals(flags, (int) sampleFlags.get(index));
  byte[] sampleEncryptionKey = sampleEncryptionKeys.get(index);
  if (encryptionKey == null) {
    Assert.assertEquals(null, sampleEncryptionKey);
  } else {
    MoreAsserts.assertEquals(encryptionKey, sampleEncryptionKey);
  }
}
 
Example #4
Source File: TextUtilsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void stringSplitterTestHelper(String string, String[] expectedStrings) {
    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(string);
    List<String> strings = Lists.newArrayList();
    for (String s : splitter) {
        strings.add(s);
    }
    MoreAsserts.assertEquals(expectedStrings, strings.toArray(new String[]{}));
}
 
Example #5
Source File: UtilsTests.java    From openwebrtc-android-sdk with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void testIntersectPayloads() {
    List<RtcPayload> emptyIntersection = Utils.intersectPayloads(sDefaultVideoPayloads, Collections.<RtcPayload>emptyList());
    MoreAsserts.assertEmpty(emptyIntersection);
}
 
Example #6
Source File: MyApplicationTest.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void testCorrectVersion() throws Exception {
    PackageInfo info = application.getPackageManager().getPackageInfo(application.getPackageName(), 0);
    assertNotNull(info);
    MoreAsserts.assertMatchesRegex("\\d\\.\\d", info.versionName);
}
 
Example #7
Source File: ApplicationTest.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void testCorrectVersion() throws Exception {
    PackageInfo info = application.getPackageManager().getPackageInfo(application.getPackageName(), 0);
    assertNotNull(info);
    MoreAsserts.assertMatchesRegex("\\d\\.\\d", info.versionName);
}
 
Example #8
Source File: UtilsTest.java    From ploggy with GNU General Public License v3.0 4 votes vote down vote up
public void testDateFormatter_formatRelativeDatetime() {
    // We'll force the use of a date, otherwise tests will fail if run
    // between midnight and 1am (because there'll be no time that's "greater
    // than an hour" but also "within the same day".
    Calendar calNow = new GregorianCalendar(TimeZone.getDefault());
    calNow.set(2013, 10, 22, 23, 01, 02); // Friday 2013-11-22T23:01:02 (local TZ)

    Date within1Minute = new Date(calNow.getTimeInMillis() - 30000);
    Date within1Hour = new Date(calNow.getTimeInMillis() - 1800000);
    Date withinSameDay = new Date(calNow.getTimeInMillis() - 9000000);
    Date withinSameWeek = new Date(calNow.getTimeInMillis() - 259200000);
    Date withinSameYear = new Date(calNow.getTimeInMillis() - 1036800000);
    Date moreThanSameYear = new Date(calNow.getTimeInMillis() - 34560000000L);

    // TODO: Make these locale-friendly? (Without just duplicating the function being tested...)

    // ago = false

    MoreAsserts.assertContainsRegex(
            "^\\d{1,2} secs$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), within1Minute, calNow.getTime(), false));

    MoreAsserts.assertContainsRegex(
            "^\\d{1,2} mins$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), within1Hour, calNow.getTime(), false));

    MoreAsserts.assertContainsRegex(
            "^\\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameDay, calNow.getTime(), false));

    MoreAsserts.assertContainsRegex(
            "^\\w{3}, \\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameWeek, calNow.getTime(), false));

    MoreAsserts.assertContainsRegex(
            "^\\w{3} \\d{1,2}, \\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameYear, calNow.getTime(), false));

    MoreAsserts.assertContainsRegex(
            "^\\w{3} \\d{1,2} \\d{4}, \\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), moreThanSameYear, calNow.getTime(), false));

    // ago = true

    MoreAsserts.assertContainsRegex(
            "^\\d{1,2} secs ago$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), within1Minute, calNow.getTime(), true));

    MoreAsserts.assertContainsRegex(
            "^\\d{1,2} mins ago$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), within1Hour, calNow.getTime(), true));

    MoreAsserts.assertContainsRegex(
            "^\\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameDay, calNow.getTime(), true));

    MoreAsserts.assertContainsRegex(
            "^\\w{3}, \\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameWeek, calNow.getTime(), true));

    MoreAsserts.assertContainsRegex(
            "^\\w{3} \\d{1,2}, \\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameYear, calNow.getTime(), true));

    MoreAsserts.assertContainsRegex(
            "^\\w{3} \\d{1,2} \\d{4}, \\d{1,2}:\\d{2} (AM|PM)$",
            Utils.DateFormatter.formatRelativeDatetime(getContext(), moreThanSameYear, calNow.getTime(), true));

    /*
    Date start = new Date();
    int i = 0;
    for (; i < 100; i++) {
        Utils.DateFormatter.formatRelativeDatetime(getContext(), within1Minute, calNow.getTime(), true);
        Utils.DateFormatter.formatRelativeDatetime(getContext(), within1Hour, calNow.getTime(), true);
        Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameDay, calNow.getTime(), true);
        Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameWeek, calNow.getTime(), true);
        Utils.DateFormatter.formatRelativeDatetime(getContext(), withinSameYear, calNow.getTime(), true);
        Utils.DateFormatter.formatRelativeDatetime(getContext(), moreThanSameYear, calNow.getTime(), true);
    }
    Date end = new Date();
    Log.i(this.getName(), String.format("%d iterations: %d ms", i, end.getTime() - start.getTime()));
    */
}