@Test
public void testWrapNoPrimaryThrows() throws Exception {

  byte[] primaryKeyValue = Random.randBytes(KEY_SIZE);
  Keyset.Key primary =
      TestUtil.createKey(
          TestUtil.createPrfKeyData(primaryKeyValue),
          /* keyId= */ 5,
          KeyStatusType.ENABLED,
          OutputPrefixType.RAW);
  final Prf unusedPrf =
      new Prf() {
        @Override
        public byte[] compute(byte[] input, int outputLength) throws GeneralSecurityException {
          return new byte[0];
        }
      };
  final PrimitiveSet<PrfSet> primitiveSet = PrimitiveSet.newPrimitiveSet(PrfSet.class);
  primitiveSet.addPrimitive(
      new PrfSet() {
        @Override
        public int getPrimaryId() {
          return 0;
        }
        @Override
        public Map<Integer, Prf> getPrfs() throws GeneralSecurityException {
          HashMap<Integer, Prf> prfMap = new HashMap<>();
          prfMap.put(0, unusedPrf);
          return prfMap;
        }
      },
      primary);
  // Note: Added a primary key but did not call primitiveSet.setPrimary().
  assertThrows(
      GeneralSecurityException.class,
      new ThrowingRunnable() {
        @Override
        public void run() throws Throwable {
          new PrfSetWrapper().wrap(primitiveSet);
        }
      });
}