@Test public void setUpApplicationState_shouldCreateStorageDirs() throws Exception { bootstrapWrapper.callSetUpApplicationState(); ApplicationInfo applicationInfo = ApplicationProvider.getApplicationContext() .getApplicationInfo(); assertThat(applicationInfo.sourceDir).isNotNull(); assertThat(new File(applicationInfo.sourceDir).exists()).isTrue(); assertThat(applicationInfo.publicSourceDir).isNotNull(); assertThat(new File(applicationInfo.publicSourceDir).exists()).isTrue(); assertThat(applicationInfo.dataDir).isNotNull(); assertThat(new File(applicationInfo.dataDir).isDirectory()).isTrue(); }
@Test @Config(minSdk = Build.VERSION_CODES.N) public void setUpApplicationState_shouldCreateStorageDirs_Nplus() throws Exception { bootstrapWrapper.callSetUpApplicationState(); ApplicationInfo applicationInfo = ApplicationProvider.getApplicationContext() .getApplicationInfo(); assertThat(applicationInfo.credentialProtectedDataDir).isNotNull(); assertThat(new File(applicationInfo.credentialProtectedDataDir).isDirectory()).isTrue(); assertThat(applicationInfo.deviceProtectedDataDir).isNotNull(); assertThat(new File(applicationInfo.deviceProtectedDataDir).isDirectory()).isTrue(); }
@Test public void testSerializerGetType() { DownloadAction action = createDownloadAction(uri1); assertThat(action.type).isNotNull(); }
@Test public void testSerializerGetType() { DownloadAction action = createDownloadAction(uri1); assertThat(action.type).isNotNull(); }
@Test public void testSerializerGetType() { DownloadAction action = createDownloadAction(uri1); assertThat(action.type).isNotNull(); }
@Test public void testSerializerGetType() throws Exception { DownloadAction action = createDownloadAction(uri1, null); assertThat(action.type).isNotNull(); }
@Test public void addPackageSetsStorage() throws Exception { shadowPackageManager.addPackage("test.package"); PackageInfo packageInfo = packageManager.getPackageInfo("test.package", 0); assertThat(packageInfo.applicationInfo.sourceDir).isNotNull(); assertThat(new File(packageInfo.applicationInfo.sourceDir).exists()).isTrue(); assertThat(packageInfo.applicationInfo.publicSourceDir) .isEqualTo(packageInfo.applicationInfo.sourceDir); }
@Test public void testGenerateKey() throws Exception { assertThat(generateKey(EMPTY)).isNotNull(); Uri testUri = Uri.parse("test"); String key = CacheUtil.generateKey(testUri); assertThat(key).isNotNull(); // Should generate the same key for the same input assertThat(generateKey(testUri)).isEqualTo(key); // Should generate different key for different input assertThat(key.equals(generateKey(parse("test2")))).isFalse(); }
@Test public void shouldSetUpSystemResources() { Resources systemResources = Resources.getSystem(); Resources appResources = ApplicationProvider.getApplicationContext().getResources(); assertThat(systemResources).named("system resources").isNotNull(); assertThat(systemResources.getString(android.R.string.copy)).named("system resource") .isEqualTo(appResources.getString(android.R.string.copy)); assertThat(appResources.getString(R.string.howdy)).named("app resource") .isNotNull(); try { systemResources.getString(R.string.howdy); fail("Expected Exception not thrown"); } catch (Resources.NotFoundException e) { } }
@Test public void name_getAndSet() throws Exception { // The name shouldn't be null, even before we set anything. assertThat(bluetoothAdapter.getName()).isNotNull(); bluetoothAdapter.setName("Foo"); assertThat(bluetoothAdapter.getName()).isEqualTo("Foo"); }
@Test public void testGetDiskType() { DiskType diskType = diskTypeClient.getDiskType(ProjectZoneDiskTypeName.of(DISK_TYPE, DEFAULT_PROJECT, ZONE)); ProjectZoneDiskTypeName returnDiskName = ProjectZoneDiskTypeName.parse(diskType.getSelfLink()); assertThat(returnDiskName.getZone()).isEqualTo(ZONE); assertThat(returnDiskName.getDiskType()).isEqualTo(DISK_TYPE); assertThat(diskType.getCreationTimestamp()).isNotNull(); assertThat(diskType.getDescription()).isNotNull(); assertThat(diskType.getValidDiskSize()).isNotNull(); assertThat(diskType.getDefaultDiskSizeGb()).isNotNull(); }
@Test public void testListDiskTypes() { Page<DiskType> diskPage = diskTypeClient.listDiskTypes(ProjectZoneName.of(DEFAULT_PROJECT, ZONE)).getPage(); Iterator<DiskType> diskTypeIterator = diskPage.iterateAll().iterator(); assertThat(diskTypeIterator.hasNext()).isTrue(); while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); assertThat(diskType.getSelfLink()).isNotNull(); ProjectZoneDiskTypeName returnDiskName = ProjectZoneDiskTypeName.parse(diskType.getSelfLink()); assertThat(returnDiskName.getZone()).isEqualTo(ZONE); assertThat(diskType.getCreationTimestamp()).isNotNull(); assertThat(diskType.getDescription()).isNotNull(); assertThat(diskType.getValidDiskSize()).isNotNull(); assertThat(diskType.getDefaultDiskSizeGb()).isNotNull(); } }
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(); } } }
@Test public void testAggregatedListDiskTypes() { AggregatedListDiskTypesPagedResponse pagedListResponse = diskTypeClient.aggregatedListDiskTypes(ProjectName.of(DEFAULT_PROJECT)); List<DiskTypesScopedList> diskTypeScopedListIterator = Lists.newArrayList(pagedListResponse.iterateAll()); List<DiskType> diskTypeIterator = new LinkedList<>(); for (DiskTypesScopedList scopedList : diskTypeScopedListIterator) { diskTypeIterator.addAll(scopedList.getDiskTypesList()); } assertThat(diskTypeIterator.size()).isGreaterThan(0); for (DiskType diskType : diskTypeIterator) { assertThat(diskType.getRegion() != null || diskType.getZone() != null).isTrue(); if (diskType.getRegion() != null) { ProjectRegionDiskTypeName zoneName = ProjectRegionDiskTypeName.parse(diskType.getSelfLink()); assertThat(zoneName.getDiskType()).isNotNull(); assertThat(zoneName.getRegion()).isNotNull(); } else { ProjectZoneDiskTypeName zoneName = ProjectZoneDiskTypeName.parse(diskType.getSelfLink()); assertThat(zoneName.getDiskType()).isNotNull(); assertThat(zoneName.getZone()).isNotNull(); } assertThat(diskType.getCreationTimestamp()).isNotNull(); assertThat(diskType.getDescription()).isNotNull(); assertThat(diskType.getValidDiskSize()).isNotNull(); assertThat(diskType.getDefaultDiskSizeGb()).isNotNull(); } } }
@Test public void testListDiskTypesWithFilter() { ListDiskTypesHttpRequest request = ListDiskTypesHttpRequest.newBuilder() .setZone(ProjectZoneName.of(DEFAULT_PROJECT, ZONE).toString()) .setFilter("(defaultDiskSizeGb = 375)") .build(); Page<DiskType> diskPage = diskTypeClient.listDiskTypes(request).getPage(); Iterator<DiskType> diskTypeIterator = diskPage.iterateAll().iterator(); assertThat(diskTypeIterator.hasNext()).isTrue(); while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); assertThat(diskType.getZone()).isNotNull(); ProjectZoneName zoneName = ProjectZoneName.parse(diskType.getZone()); assertThat(zoneName.getZone()).isEqualTo(ZONE); assertThat(diskType.getCreationTimestamp()).isNotNull(); assertThat(diskType.getDescription()).isNotNull(); assertThat(diskType.getValidDiskSize()).isNotNull(); assertThat(diskType.getDefaultDiskSizeGb()).isNotNull(); } }
/** * <a href="https://github.com/robolectric/robolectric/issues/2773">Issue</a> */ @Test public void getResourceAsStream() throws Exception { Phonenumber.PhoneNumber phoneNumber = new Phonenumber.PhoneNumber(); phoneNumber.setCountryCode(7); phoneNumber.setNationalNumber(4956360636L); String format = PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL); assertThat(format).isNotNull(); } }
@Test public void shouldRecordAcceptCookie() { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setCookie("foo", "bar"); cookieManager.setCookie("baz", "qux"); assertThat(cookieManager.getCookie("foo")).isNotNull(); cookieManager.removeAllCookie(); assertThat(cookieManager.getCookie("foo")).isNull(); assertThat(cookieManager.getCookie("baz")).isNull(); }
@SuppressWarnings("unchecked") @Test public void nestedCollection() { List<ArrayList<Set<Map<String, List<String>>>>>[] array = (List<ArrayList<Set<Map<String, List<String>>>>>[])new List<?>[] {getStringListMapSetArrayListList() }; NestedCollectionModel model = new NestedCollectionModel(); model.crazyCollection = array; String json = null; try { json = LoganSquare.serialize(model); } catch (Exception e) { e.printStackTrace(); } ASSERT.that(json).isNotNull(); NestedCollectionModel reconstructedModel = null; try { reconstructedModel = LoganSquare.parse(json, NestedCollectionModel.class); } catch (Exception ignored) { } // Comparing the json doesn't work so well on arrays, since they could be reordered. We'll compare the output instead. ASSERT.that(model.equals(reconstructedModel)).isTrue(); }
@Test public void testNullSchema() { TableResult result = new TableResult(null, 3, INNER_PAGE_0); assertThat(result.getSchema()).isNull(); assertThat(result.hasNextPage()).isTrue(); assertThat(result.getNextPageToken()).isNotNull(); assertThat(result.getValues()) .containsExactly(newFieldValueList("0"), newFieldValueList("1")) .inOrder(); TableResult next = result.getNextPage(); assertThat(next.getSchema()).isNull(); assertThat(next.hasNextPage()).isFalse(); assertThat(next.getNextPageToken()).isNull(); assertThat(next.getValues()).containsExactly(newFieldValueList("2")); assertThat(next.getNextPage()).isNull(); assertThat(result.iterateAll()) .containsExactly(newFieldValueList("0"), newFieldValueList("1"), newFieldValueList("2")) .inOrder(); }
@Test public void testSchema() { TableResult result = new TableResult(SCHEMA, 3, INNER_PAGE_0); assertThat(result.getSchema()).isEqualTo(SCHEMA); assertThat(result.hasNextPage()).isTrue(); assertThat(result.getNextPageToken()).isNotNull(); assertThat(result.getValues()) .containsExactly( newFieldValueList("0").withSchema(SCHEMA.getFields()), newFieldValueList("1").withSchema(SCHEMA.getFields())) .inOrder(); TableResult next = result.getNextPage(); assertThat(next.getSchema()).isEqualTo(SCHEMA); assertThat(next.hasNextPage()).isFalse(); assertThat(next.getNextPageToken()).isNull(); assertThat(next.getValues()) .containsExactly(newFieldValueList("2").withSchema(SCHEMA.getFields())); assertThat(next.getNextPage()).isNull(); assertThat(result.iterateAll()) .containsExactly( newFieldValueList("0").withSchema(SCHEMA.getFields()), newFieldValueList("1").withSchema(SCHEMA.getFields()), newFieldValueList("2").withSchema(SCHEMA.getFields())) .inOrder(); } }