@Test public void testLogError() { BuckEventBus eventBus = BuckEventBusFactory.newInstance(); CapturingConsoleEventListener listener = new CapturingConsoleEventListener(); eventBus.register(listener); BuildContext buildContext = BuildContext.builder() .setActionGraph(createMock(ActionGraph.class)) .setStepRunner(createMock(StepRunner.class)) .setProjectFilesystem(createMock(ProjectFilesystem.class)) .setArtifactCache(createMock(ArtifactCache.class)) .setJavaPackageFinder(createMock(JavaPackageFinder.class)) .setEventBus(eventBus) .build(); buildContext.logError(new RuntimeException(), "Error detail: %s", "BUILD_ID"); assertEquals(ImmutableList.of("Error detail: BUILD_ID"), listener.getLogMessages()); }
@Test(expected = HumanReadableException.class) public void testGetAndroidBootclasspathSupplierWithoutAndroidPlatformTarget() { BuildContext.Builder builder = BuildContext.builder(); // Set to non-null values. builder.setActionGraph(createMock(ActionGraph.class)); builder.setStepRunner(createMock(StepRunner.class)); builder.setProjectFilesystem(createMock(ProjectFilesystem.class)); builder.setArtifactCache(createMock(ArtifactCache.class)); builder.setJavaPackageFinder(createMock(JavaPackageFinder.class)); builder.setEventBus(BuckEventBusFactory.newInstance()); BuildContext context = builder.build(); Supplier<String> androidBootclasspathSupplier = context.getAndroidBootclasspathSupplier(); // If no AndroidPlatformTarget is passed to the builder, it should return a Supplier whose get() // method throws an exception. androidBootclasspathSupplier.get(); }
@Test public void testGetAndroidBootclasspathSupplierWithAndroidPlatformTarget() { BuildContext.Builder builder = BuildContext.builder(); // Set to non-null values. builder.setActionGraph(createMock(ActionGraph.class)); builder.setStepRunner(createMock(StepRunner.class)); builder.setProjectFilesystem(createMock(ProjectFilesystem.class)); builder.setArtifactCache(createMock(ArtifactCache.class)); builder.setJavaPackageFinder(createMock(JavaPackageFinder.class)); builder.setEventBus(BuckEventBusFactory.newInstance()); AndroidPlatformTarget androidPlatformTarget = createMock(AndroidPlatformTarget.class); List<Path> entries = ImmutableList.of( Paths.get("add-ons/addon-google_apis-google-15/libs/effects.jar"), Paths.get("add-ons/addon-google_apis-google-15/libs/maps.jar"), Paths.get("add-ons/addon-google_apis-google-15/libs/usb.jar")); expect(androidPlatformTarget.getBootclasspathEntries()).andReturn(entries); replay(androidPlatformTarget); builder.setAndroidBootclasspathForAndroidPlatformTarget(Optional.of(androidPlatformTarget)); BuildContext context = builder.build(); Supplier<String> androidBootclasspathSupplier = context.getAndroidBootclasspathSupplier(); String androidBootclasspath = MorePaths.pathWithUnixSeparators(androidBootclasspathSupplier.get()); assertEquals( "add-ons/addon-google_apis-google-15/libs/effects.jar:" + "add-ons/addon-google_apis-google-15/libs/maps.jar:" + "add-ons/addon-google_apis-google-15/libs/usb.jar", androidBootclasspath); // Call get() again to ensure that the underlying getBootclasspathEntries() is not called again // to verify that memoization is working as expected. androidBootclasspathSupplier.get(); verify(androidPlatformTarget); }