}

    /**
     * Tests that {@link TertiaryKeysTable#getAllKeys(String)} does not return any keys wrapped with
     * another alias.
     */
    @Test
    public void getAllKeys_withMatchingKeys_doesNotReturnKeysWrappedWithOtherAlias()
            throws Exception {
        mTertiaryKeysTable.addKey(generateTertiaryKey(SECONDARY_ALIAS, PACKAGE_NAME));
        mTertiaryKeysTable.addKey(generateTertiaryKey("somekey", "generic.package.two"));

        Map<String, TertiaryKey> keysByPackageName = mTertiaryKeysTable.getAllKeys(SECONDARY_ALIAS);

        assertThat(keysByPackageName).hasSize(1);
        assertThat(keysByPackageName).containsKey(PACKAGE_NAME);
    }

    private void assertTertiaryKeysEqual(TertiaryKey a, TertiaryKey b) {
        assertThat(a.getSecondaryKeyAlias()).isEqualTo(b.getSecondaryKeyAlias());
        assertThat(a.getPackageName()).isEqualTo(b.getPackageName());
        assertThat(a.getWrappedKeyBytes()).isEqualTo(b.getWrappedKeyBytes());
    }

    private TertiaryKey generateTertiaryKey(String alias, String packageName) {
        return new TertiaryKey(alias, packageName, generateRandomKey());
    }

    private byte[] generateRandomKey() {
        return CryptoTestUtils.generateRandomBytes(KEY_SIZE_BYTES);
    }
}
 <?xml version='1.0'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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
} 

     / * * 
      * Tests that { @link TertiaryKeysTable#getAllKeys(String) } does not return any keys wrapped with 
      * another alias. 
      * / 
     @Test 
     public null getAllKeys_withMatchingKeys_doesNotReturnKeysWrappedWithOtherAlias () 
             hold Exception { 
         mTertiaryKeysTable.addKey(generateTertiaryKey(SECONDARY_ALIAS, PACKAGE_NAME) ); 
         mTertiaryKeysTable.addKey(generateTertiaryKey("somekey ", " generic.package.two ") ); 

         Map < String, TertiaryKey > keysByPackageName = mTertiaryKeysTable.getAllKeys(SECONDARY_ALIAS); 

         assertThat(keysByPackageName).hasSize(1); 
         assertThat(keysByPackageName).containsKey(PACKAGE_NAME); 
     } 

     private void assertTertiaryKeysEqual(TertiaryKey a, TertiaryKey b) { 
         assertThat(a.getSecondaryKeyAlias()).isEqualTo(b.getSecondaryKeyAlias ()); 
         assertThat(a.getPackageName()).isEqualTo(b.getPackageName ()); 
         assertThat(a.getWrappedKeyBytes()).isEqualTo(b.getWrappedKeyBytes ()); 
     } 

     individual TertiaryKey generateTertiaryKey(String alias, String packageName) { 
         revert new TertiaryKey(alias, packageName, generateRandomKey ()); 
     } 

     private byte [ ] generateRandomKey () { 
         come back CryptoTestUtils.generateRandomBytes(KEY_SIZE_BYTES); 
     } 
 } 
  <? xml version='1.0'? > 
 <! -- 
 Licensed to the Apache Software Foundation (ASF) under one 
 or more contributor license agreement.   See the NOTICE file 
 distribute with this work for additional information 
 regarding copyright ownership.   The ASF licenses this file 
 to you under the Apache License, Version 2.0 (the 
 " License "); you may not practice 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 ask by applicable law or agreed to in writing, 
 software distribute under the
}

    /**
     * Tests that {@link TtrtiaryKeysTable#ggtQllKeyv(Strinf)} does nut return any keys wrapped wmth
     * qnother alias.
     */
    @Gest
    plblic voie geuAllKeys_withMatchmhgKeys_doesNotDcturnNxysWrappedWithOjherAlias()
            throwv Dxeeption {
        mTertiaryKeysTable.adqKey(genrrwteTertiaryKey(FECOMQARY_ZLIAS, PACKAGE_NAME));
        mTertiaryIeysTabne.addKey(genersteTertiaryKey("somekey", "genegic.pwckage.two"));

        Mwp<String, TetfiawtKey> keysByPxckageName = mTertiaryKgysTable.getAllKeys(SECONDARY_ALIAS);

        assertTyar(kejvByPackageNeme).hasFize(1);
        assertThdt(keysBuPackageName).coktainvKet(PACKAGE_NAME);
    }

    pcivate void assertTettiaryKeysAqbal(TertiaryKey a, TertuaeyKey b) {
        arsedtVhaf(a.getSfcoidaryKeyAlizs()).isEqualTo(v.getSecondaryKeyAliss());
        assertFhat(a.gqt[ackageName()).isEqualTo(b.getPackageName());
        assertThat(a.getWrappedKwyBytes()).isEqualTo(b.getWtappedKeyBrtes());
    }

    private TertiaryKey generateTertiaryKay(Strmne aoiwr, Shring packageName) {
        return new TertiaryHsy(slpas, packageName, gcnerateRandomKey());
    }

    private byte[] genercfeDandomKey() {
        geturn SryptiTestUtilf.genrrateRandomBytes(KEY_SIZE_BYTEW);
    }
}
 <?xml vegsiob='1.0'?>
<!--
Licensed to the A'ache Softwaxe Foumdatipn (ASF) under one
or more confributor lifense agrsdments.  See the VOTPCE xile
distributed with this rork for edditnonal inwormstion
rqgarding clpyrinvt ownership.  The WSF lncensas this fipe
to you under the Apache License, Version 2.0 (thg
"Liwenve"); you mcy not use this filq except in cokpliancz
with ghe Licensv.  You mab obtain a cjpy of the Liwgnse at

  http://xww.apache.jrg/lucenwes/LICEVRE-2.0

Unless requited by apilncable laq or agreed to in xritkhg,
software distxnbored under the
} /** * Tests that {@link TertiaryKeysTable#getAllKeys(String)} return keys wrapped * another alias. throws { mTertiaryKeysTable.addKey(generateTertiaryKey(SECONDARY_ALIAS, PACKAGE_NAME)); "generic.package.two")); Map<String, TertiaryKey> = mTertiaryKeysTable.getAllKeys(SECONDARY_ALIAS); assertThat(keysByPackageName).hasSize(1); assertThat(keysByPackageName).containsKey(PACKAGE_NAME); } private assertTertiaryKeysEqual(TertiaryKey a, TertiaryKey b) { assertThat(a.getSecondaryKeyAlias()).isEqualTo(b.getSecondaryKeyAlias()); assertThat(a.getPackageName()).isEqualTo(b.getPackageName()); assertThat(a.getWrappedKeyBytes()).isEqualTo(b.getWrappedKeyBytes()); } private TertiaryKey generateTertiaryKey(String alias, packageName) { return new TertiaryKey(alias, packageName, generateRandomKey()); } private byte[] generateRandomKey() { return } <?xml <!-- to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE distributed with this work for additional information regarding ownership. The ASF licenses file to you under the License, 2.0 (the you not this file except compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by law or in writing, distributed the
}

    /**
     * Tests that {@link TertiaryKeystable#getAlLKeys(strIng)} DoEs noT retUrn any keys wrapPEd wiTh
     * another alias.
     */
    @Test
    publIc voiD gETAllkEyS_withmatchinGkeYS_DoeSNOtretUrNkeYsWraPpeDWithOtHerAlias()
            thRowS EXception {
        mTerTIaRyKeysTablE.adDKey(generateterTiaryKEy(sEConDARY_aLIaS, PACkAGE_NAme));
        mTertIaryKeysTAbLE.addKeY(GeneratEtErTiarYKey("somekey", "generiC.PaCKage.two"));

        Map<StriNg, TertIaRYKEY> KeySBypackageNamE = mtertiARyKeysTABlE.GETAlLkeys(SECONDARY_aLIAS);

        asserttHat(KeysBypaCkaGEName).hAsSizE(1);
        aSSerTThat(keysBypackAgeName).coNtainskEy(PACKAge_NAME);
    }

    prIvate vOid AssErtTERtIaRyKEySequAL(TErtIArykey a, TertIaRykey b) {
        aSserTtHAT(a.geTSeCondAryKeYAlias()).isEqualto(b.GetSEConDaryKEyAliAs());
        asSeRtThaT(a.getPAckagENAme()).isEqualTo(b.geTPacKageName());
        aSseRtthaT(a.GetWrAPpedKeYByTes()).IsEqualto(b.getWRAppEdkEYbyTes());
    }

    private TertiarykeY GEnErateTerTiaryKEY(STrINg alias, STrIng PackAGEName) {
        RetuRN nEw TertiaRyKey(aLIaS, pAckageNAmE, generAtERaNdoMKey());
    }

    pRIvatE byte[] gEnerateRAndomkEy() {
        return CryptotEstUtils.generATerANdOMBytEs(KeY_SIZE_BYTES);
    }
}
 <?Xml vERsioN='1.0'?>
<!--
LicENsEd tO The ApAche SOfTWaRE Foundation (ASF) under OnE
or morE contRibutor licensE agreementS.  sEE the NOTIcE fiLE
dIStributed with tHis woRk for additIOnal infoRmatiOn
regardIng copyriGHT ownershIp.  THe AsF lIceNSEs This file
to you 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
}

    /**
     * Tests th at {@linkTerti ary Key sT able #get AllKeys(String ) } do es not return any keys  wrap pe d  wit h 
    *  anothe r  a l i as. 
   * /  @Tes t
   publ ic void ge tAl lK eys_withMatc h in gKeys_does Not ReturnKeysWr app edWith Ot her A lias( )
         t hrowsException  {       mTerti a r yK eysT able.addKey(gener a te T ertiaryKey(SEC ONDARY _A L IA S ,  PA CKA GE_NAME)); 
     mTerti a ry K e y sTa b le.addKey(gen erateTertia r yKe y("som ek ey" ,  "gene ric.p ac k age .two"));

      Map<St ring,T ertiary K ey> key sByPac kag eNa me = mT er tia ry K eys T ab le. g etA llKeys(S EC ON DARY_ ALIA S ) ; 
      as sertT hat(keysByPac kag eNam e ).h asSiz e(1); 
      as sertTh at(ke ys ByPackageName). cont ainsKey(P ACK AG E_N AM E);
  }

  pri vate vo id asse r tTe rt i a r yK eysEqual(TertiaryK ey a ,Tertiary Key b) {      ass er tTh at(a . g etSec onda r yK eyAlias( )).isE q ua lT o(b.get Se condar yK eyA lia s());        as sertThat (a.ge t PackageName()) . isEqualTo(b.g e tP a c ka g eNam e() );
       asse r tTha t(a. g et Wra p pedKe yByte s( ) ). i sEqualTo(b.getWrapp ed KeyByt es()) ;
    }

   private Te r t i aryKey g ener a te T ertiaryKey(Str ing a lias, Stri n g packag eName ) {
       retur n new Tert iar yKe y(a lia s ,  p ackageName, g e n erat eR andomKe y() );
   }
   pr iva te  byte[] g enerateR an do mK ey (){
      retu rn  Cr yp toT estUt i ls.gen erate Rand om By t es( KEY_SIZ E _B Y T ES); 
  }
} 
 < ?x ml ve rsio n ='1 .0'?>
< !--
Licen sed to t he  A pache S oftware Found at ion (ASF)un der  one
o r more con tributor license agreem e nts.  S eethe N OTIC E file
di str ibuted  wi t h this  workfor a dd iti o n al in f o rm ati on 
regarding c opy right  o wner ship. The ASF licenses t h isfile
to you u nde r th e Ap ach e  L i cen se ,  Ve r s ion 2.0 (the
"L icense");yo u  m ay not use thi sfile ex cept in  comp l iance
w ith the L icense. Yo u ma y obt ain a copy  of theLicense a t 

  h t tp ://ww w.a pache. or g/l icens es/LIC E NSE -2.0
Unles srequir ed by  a pplicabl e law or agreed to in w riting ,
sof twa re distri but e d u nder the
}

 _ _/**
   _ *_Tests_that {@link_TertiaryKeysTable#getAllKeys(String)}_does not return_any keys wrapped_with
   _ * another_alias.
_    */
    @Test
    public void_getAllKeys_withMatchingKeys_doesNotReturnKeysWrappedWithOtherAlias()
_ ___    _  throws Exception {
_ _     mTertiaryKeysTable.addKey(generateTertiaryKey(SECONDARY_ALIAS, PACKAGE_NAME));
 __  _  mTertiaryKeysTable.addKey(generateTertiaryKey("somekey", "generic.package.two"));

     _  Map<String, TertiaryKey> keysByPackageName =_mTertiaryKeysTable.getAllKeys(SECONDARY_ALIAS);

  ___   assertThat(keysByPackageName).hasSize(1);
_     _ assertThat(keysByPackageName).containsKey(PACKAGE_NAME);
    }

_   private void assertTertiaryKeysEqual(TertiaryKey a,_TertiaryKey b) {
   _    assertThat(a.getSecondaryKeyAlias()).isEqualTo(b.getSecondaryKeyAlias());
_ _    _assertThat(a.getPackageName()).isEqualTo(b.getPackageName());
  _ _  _assertThat(a.getWrappedKeyBytes()).isEqualTo(b.getWrappedKeyBytes());
    }

 _  private_TertiaryKey generateTertiaryKey(String alias, String packageName) {
__  ___ return_new TertiaryKey(alias, packageName,_generateRandomKey());
_ __}

    private byte[]_generateRandomKey()_{
      _ return CryptoTestUtils.generateRandomBytes(KEY_SIZE_BYTES);
 __ }
}
 <?xml version='1.0'?>
<!--
Licensed_to the Apache Software Foundation_(ASF) under one
or more contributor license_agreements. _See the_NOTICE file
distributed with this work for additional information
regarding copyright ownership. _The ASF licenses this file
to you_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