/*
 * Copyright 2014-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.facebook.buck.android;

import com.facebook.buck.jvm.java.testutil.AbiCompilationModeTest;
import com.facebook.buck.testutil.TemporaryPaths;
import com.facebook.buck.testutil.integration.ProjectWorkspace;
import com.facebook.buck.testutil.integration.TestDataHelper;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;

public class AndroidBinaryCrossCellIntegrationTest extends AbiCompilationModeTest {

  @Rule public TemporaryPaths tmpFolder = new TemporaryPaths();

  @Test
  public void testCrossRepositoryDexMerge() throws InterruptedException, IOException {
    AssumeAndroidPlatform.assumeSdkIsAvailable();
    AssumeAndroidPlatform.assumeNdkIsAvailable();

    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(
            this, "android_binary_cross_cell_test", tmpFolder);
    workspace.setUp();
    setWorkspaceCompilationMode(workspace);

    workspace.runBuckCommand("build", "//:app", "other_repo//:app").assertSuccess();
  }

  @Test
  public void testCrossRepositoryDexMergeWithSplitDex() throws InterruptedException, IOException {
    AssumeAndroidPlatform.assumeSdkIsAvailable();
    AssumeAndroidPlatform.assumeNdkIsAvailable();

    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(
            this, "android_binary_cross_cell_test", tmpFolder);
    workspace.setUp();
    setWorkspaceCompilationMode(workspace);

    workspace
        .runBuckCommand("build", "//:app_with_main_lib", "other_repo//:app_with_mainlib")
        .assertSuccess();
  }
}

@@ -2177,11 +2177,806 @@
 s();%0A  %7D
+%0A%0A  @Test%0A  public void testBuildingBinariesSeparately() throws InterruptedException, IOException %7B%0A    AssumeAndroidPlatform.assumeSdkIsAvailable();%0A    AssumeAndroidPlatform.assumeNdkIsAvailable();%0A%0A    ProjectWorkspace workspace =%0A        TestDataHelper.createProjectWorkspaceForScenario(%0A            this, %22android_binary_cross_cell_test%22, tmpFolder);%0A    workspace.setUp();%0A    workspace.enableDirCache();%0A    setWorkspaceCompilationMode(workspace);%0A%0A    workspace.runBuckCommand(%22build%22, %22other_repo//:app_with_mainlib%22).assertSuccess();%0A    workspace.runBuckCommand(%22clean%22, %22--keep-cache%22).assertSuccess();%0A    workspace.runBuckCommand(%22build%22, %22//:app_with_main_lib%22).assertSuccess();%0A    workspace.getBuildLog().assertTargetWasFetchedFromCache(%22//java/com/sample/mainlib:mainlib%22);%0A  %7D
 %0A%7D%0A

Test to make sure intermediate targets aren't rebuild when building cross-cell