Home | History | Annotate | Download | only in suite
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.tradefed.testtype.suite;
     17 
     18 /**
     19  * Helper class for operation related to merging {@link ITestSuite} and {@link ModuleDefinition}
     20  * after a split.
     21  */
     22 public class ModuleMerger {
     23 
     24     private static void mergeModules(ModuleDefinition module1, ModuleDefinition module2) {
     25         if (!module1.getId().equals(module2.getId())) {
     26             throw new IllegalArgumentException(
     27                     String.format(
     28                             "Modules must have the same id to be mergeable: received %s and "
     29                                     + "%s",
     30                             module1.getId(), module2.getId()));
     31         }
     32         module1.addTests(module2.getTests());
     33     }
     34 
     35     /**
     36      * Merge the modules from one suite to another.
     37      *
     38      * @param suite1 the suite that will receive the module from the other.
     39      * @param suite2 the suite that will give the module.
     40      */
     41     public static void mergeSplittedITestSuite(ITestSuite suite1, ITestSuite suite2) {
     42         if (suite1.getDirectModule() == null) {
     43             throw new IllegalArgumentException("suite was not a splitted suite.");
     44         }
     45         if (suite2.getDirectModule() == null) {
     46             throw new IllegalArgumentException("suite was not a splitted suite.");
     47         }
     48         mergeModules(suite1.getDirectModule(), suite2.getDirectModule());
     49     }
     50 
     51     /** Returns true if the two suites are part of the same original split. False otherwise. */
     52     public static boolean arePartOfSameSuite(ITestSuite suite1, ITestSuite suite2) {
     53         if (suite1.getDirectModule() == null) {
     54             return false;
     55         }
     56         if (suite2.getDirectModule() == null) {
     57             return false;
     58         }
     59         if (!suite1.getDirectModule().getId().equals(suite2.getDirectModule().getId())) {
     60             return false;
     61         }
     62         return true;
     63     }
     64 }
     65