@Test public void shouldWriteToExternalCacheDir() throws Exception { assertThat(context.getExternalCacheDir()).isNotNull(); File cacheTest = new File(context.getExternalCacheDir(), "__test__"); assertThat(cacheTest.getAbsolutePath()) .startsWith(System.getProperty("java.io.tmpdir")); assertThat(cacheTest.getAbsolutePath()) .endsWith(File.separator + "__test__"); try (FileOutputStream fos = new FileOutputStream(cacheTest)) { fos.write("test".getBytes(UTF_8)); } assertThat(cacheTest.exists()).isTrue(); }
@Test public void shouldWriteToCacheDir() throws Exception { assertThat(context.getCacheDir()).isNotNull(); File cacheTest = new File(context.getCacheDir(), "__test__"); assertThat(cacheTest.getAbsolutePath()) .startsWith(System.getProperty("java.io.tmpdir")); assertThat(cacheTest.getAbsolutePath()) .endsWith(File.separator + "__test__"); try (FileOutputStream fos = new FileOutputStream(cacheTest)) { fos.write("test".getBytes(UTF_8)); } assertThat(cacheTest.exists()).isTrue(); }
public void testGetClassPathUrls() throws Exception { String oldPathSeparator = PATH_SEPARATOR.value(); String oldClassPath = JAVA_CLASS_PATH.value(); System.setProperty(PATH_SEPARATOR.key(), ":"); System.setProperty( JAVA_CLASS_PATH.key(), Joiner.on(":") .join( "relative/path/to/some.jar", "/absolute/path/to/some.jar", "relative/path/to/class/root", "/absolute/path/to/class/root")); try { ImmutableList<URL> urls = ClassPath.Scanner.parseJavaClassPath(); assertThat(urls.get(0).getProtocol()).isEqualTo("file"); assertThat(urls.get(0).getAuthority()).isNull(); assertThat(urls.get(0).getPath()).endsWith("/relative/path/to/some.jar"); assertThat(urls.get(1)).isEqualTo(new URL("file:///absolute/path/to/some.jar")); assertThat(urls.get(2).getProtocol()).isEqualTo("file"); assertThat(urls.get(2).getAuthority()).isNull(); assertThat(urls.get(2).getPath()).endsWith("/relative/path/to/class/root"); assertThat(urls.get(3)).isEqualTo(new URL("file:///absolute/path/to/class/root")); assertThat(urls).hasSize(4); } finally { System.setProperty(PATH_SEPARATOR.key(), oldPathSeparator); System.setProperty(JAVA_CLASS_PATH.key(), oldClassPath); } }
@Test public void getExternalFilesDir_shouldCreateNamedDirectory() throws Exception { File f = context.getExternalFilesDir("__test__"); assertThat(f.exists()).isTrue(); assertThat(f.getAbsolutePath()).endsWith("__test__"); }
public void testImmediateFailedFuture() throws Exception { Exception exception = new Exception(); ListenableFuture<String> future = immediateFailedFuture(exception); assertThat(future.toString()).endsWith("[status=FAILURE, cause=[" + exception + "]]"); try { getDone(future); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } try { getDoneFromTimeoutOverload(future); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } }
@GwtIncompatible // immediateCheckedFuture public void testImmediateCheckedFuture() throws Exception { CheckedFuture<String, MyException> future = immediateCheckedFuture(DATA1); assertThat(future.toString()).endsWith("[status=SUCCESS, result=[" + DATA1 + "]]"); // Verify that the proper object is returned without waiting assertSame(DATA1, future.get(0L, MILLISECONDS)); assertSame(DATA1, future.checkedGet(0L, MILLISECONDS)); }
@Test public void provideProviderFails() { @Module class ProvidesProviderModule { @Provides Provider<Object> provideObject() { return null; } } try { ObjectGraph.createWith(new TestingLoader(), new ProvidesProviderModule()); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage()).startsWith("@Provides method must not return Provider directly: "); assertThat(e.getMessage()).endsWith("ProvidesProviderModule.provideObject"); } }
@Test public void provideLazyFails() { @Module class ProvidesLazyModule { @Provides Lazy<Object> provideObject() { return null; } } try { ObjectGraph.createWith(new TestingLoader(), new ProvidesLazyModule()); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage()).startsWith("@Provides method must not return Lazy directly: "); assertThat(e.getMessage()).endsWith("ProvidesLazyModule.provideObject"); } }
@Test public void provideRawProviderFails() { @Module class ProvidesRawProviderModule { @Provides Provider provideObject() { return null; } } try { ObjectGraph.createWith(new TestingLoader(), new ProvidesRawProviderModule()); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage()).startsWith("@Provides method must not return Provider directly: "); assertThat(e.getMessage()).endsWith("ProvidesRawProviderModule.provideObject"); } }
@Test public void provideRawLazyFails() { @Module class ProvidesRawLazyModule { @Provides Lazy provideObject() { return null; } } try { ObjectGraph.createWith(new TestingLoader(), new ProvidesRawLazyModule()); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage()).startsWith("@Provides method must not return Lazy directly: "); assertThat(e.getMessage()).endsWith("ProvidesRawLazyModule.provideObject"); } } }
public void testImmediateFailedFuture_cancellationException() throws Exception { CancellationException exception = new CancellationException(); ListenableFuture<String> future = immediateFailedFuture(exception); assertFalse(future.isCancelled()); assertThat(future.toString()).endsWith("[status=FAILURE, cause=[" + exception + "]]"); try { getDone(future); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } try { getDoneFromTimeoutOverload(future); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } }
@GwtIncompatible // immediateFailedCheckedFuture public void testImmediateFailedCheckedFuture() throws Exception { MyException exception = new MyException(); CheckedFuture<String, MyException> future = immediateFailedCheckedFuture(exception); assertThat(future.toString()).endsWith("[status=FAILURE, cause=[" + exception + "]]"); try { future.get(0L, MILLISECONDS); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } try { future.checkedGet(0L, MILLISECONDS); fail(); } catch (MyException expected) { assertSame(exception, expected); } }
@Test public void stringLong() { String str = "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd"; Value v = Value.string(str); assertThat(v.getString()).isEqualTo(str); assertThat(v.toString()).hasLength(32); assertThat(v.toString()).startsWith(str.substring(0, 32 - 3)); assertThat(v.toString()).endsWith("..."); }
@Test public void testHandlesRelativeRedirects() throws Exception { String expected = "fakedata"; mockWebServer .enqueue(new MockResponse().setResponseCode(301).setHeader("Location", "/redirect")); mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(expected)); getFetcher().loadData(Priority.NORMAL, callback); verify(callback).onDataReady(streamCaptor.capture()); TestUtil.assertStreamOf(expected, streamCaptor.getValue()); RecordedRequest first = mockWebServer.takeRequest(); assertThat(first.getMethod()).isEqualTo("GET"); RecordedRequest second = mockWebServer.takeRequest(); assertThat(second.getPath()).endsWith("/redirect"); assertThat(second.getMethod()).isEqualTo("GET"); }
@Test public void testByteArrayOfNonZeroCannotBeCastedToZeroes() { parcel.writeByteArray(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 1}); assertThat(parcel.dataSize()).named("total size").isEqualTo(16); parcel.setDataPosition(0); assertThat(parcel.readInt()).isEqualTo(9); try { assertThat(parcel.readInt()).isEqualTo(0); fail("expected to fail"); } catch (RuntimeException e) { assertThat(e) .hasCauseThat() .hasMessageThat() .startsWith("Looking for Integer at position 4, found byte[]"); assertThat(e) .hasCauseThat() .hasMessageThat() .endsWith("taking 12 bytes, and it is non-portable to reinterpret it"); } }
@Test public void test1_UniqueNames() { JavaFileObject source1 = new TestBuilder().build().selectName(seenNames); assertThat(source1.toUri().toString()).endsWith( "/org/inferred/freebuilder/processor/source/testing/generatedcode/TestBuilderTest.java"); JavaFileObject source2 = new TestBuilder().build().selectName(seenNames); assertThat(source2.toUri().toString()).endsWith("TestBuilderTest__2.java"); assertEquals(2, seenNames.size()); }
@Test public void getPath_withMavenProject_andNoWarSourceDirectory_returnsCanonicalMavenDir() { MavenTestUtils.getInstance() .runWithMavenModule( testFixture.getProject(), mavenModule -> { Optional<String> appEngineWebXmlDirectoryPath = directoryProvider.getAppEngineWebXmlDirectoryPath(mavenModule); assertThat(appEngineWebXmlDirectoryPath.isPresent()).isTrue(); assertThat(appEngineWebXmlDirectoryPath.get()).endsWith("/src/main/webapp/WEB-INF"); }); }
@GwtIncompatible // immediateCheckedFuture public void testImmediateCheckedFuture() throws Exception { CheckedFuture<String, MyException> future = immediateCheckedFuture( DATA1); assertThat(future.toString()) .endsWith("[status=SUCCESS, result=[" + DATA1 + "]]"); // Verify that the proper object is returned without waiting assertSame(DATA1, future.get(0L, MILLISECONDS)); assertSame(DATA1, future.checkedGet(0L, MILLISECONDS)); }
@Test public void testTinyiOS() throws Exception { ResolvedManifest resolved = ResolvedManifests.emptyAndroidArchive().manifest; BuildFindModuleFunctionTable builder = new BuildFindModuleFunctionTable(); builder.addManifest(resolved); FunctionTableExpression table = builder.build(); System.out.printf(CreateStringVisitor.convert(table)); String zip = FindModuleInterpreter.findiOS(table, resolved.cdepManifestYml.coordinate, environment.unzippedArchivesFolder .getAbsolutePath(), new String[]{"armv7"}, "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS" + ".platform/Developer/SDKs/iPhoneOS10.2.sdk").remote.getPath(); assertThat(zip).endsWith("sqlite-ios-platform-iPhone.zip"); new CMakeGenerator(environment, table).generate(); }
@Test public void testLinux() throws Exception { ResolvedManifest resolved = ResolvedManifests.sqliteLinux().manifest; BuildFindModuleFunctionTable builder = new BuildFindModuleFunctionTable(); builder.addManifest(resolved); FunctionTableExpression table = builder.build(); CreateStringVisitor.convert(table); System.out.printf(table.toString()); String zip = FindModuleInterpreter.findLinux(table, resolved.cdepManifestYml.coordinate, environment.unzippedArchivesFolder.getAbsolutePath()).remote.getPath(); assertThat(zip).endsWith("sqlite-linux.zip"); new CMakeGenerator(environment, table).generate(); ExpressionUtils.getAllFoundModuleExpressions(table); }