### Question:
RxShamir { @Nonnull public Observable<Share> createShares( @Nonnull final BigInteger secret, @Nonnull final CreationScheme creationScheme) { checkNotNull(secret, "\'secret\' must not be null."); checkNotNull(creationScheme, "\'creationScheme\' must not be null."); final Single<Polynomial> polynomial = Observable .range(1, creationScheme.getRequiredShareCount() - 1) .flatMapSingle(index -> createRandomCoefficient(creationScheme.getPrime()) .map(coefficient -> Pair.create(index, coefficient))) .startWith(Pair.create(0, secret)) .collectInto(new HashMap<Integer, BigInteger>(), (map, pair) -> map.put(pair.getKey(), pair.getValue())) .map(Polynomial::new); final Observable<Share> shares = polynomial .flatMapObservable(polynomialVal -> Observable .range(1, creationScheme.getTotalShareCount()) .map(index -> Pair.create( index, polynomialVal .evaluateAt(BigInteger.valueOf(index)) .mod(creationScheme.getPrime()))) .map(pair -> Share .builder() .setIndex(pair.getKey()) .setValue(pair.getValue()) .build())); return checkCreationInformation(secret, creationScheme).andThen(shares); } RxShamir(@Nonnull final SecureRandom random); @Nonnull static RxShamir create(@Nonnull final SecureRandom random); @Nonnull Observable<Share> createShares(
      @Nonnull final BigInteger secret,
      @Nonnull final CreationScheme creationScheme); @Nonnull Single<BigInteger> recoverSecret(
      @Nonnull final Set<Share> shares,
      @Nonnull final RecoveryScheme recoveryScheme);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testCreateShares_nullSecret() { final CreationScheme creationScheme = CreationScheme .builder() .setRequiredShareCount(2) .setTotalShareCount(2) .setPrime(7) .build(); rxShamir.createShares(null, creationScheme); }
@Test(expected = IllegalArgumentException.class) public void testCreateShares_nullCreationScheme() { rxShamir.createShares(ONE, null); }
@Test public void testCreateShares_secretLessThanPrime() { final CreationScheme creationScheme = CreationScheme .builder() .setRequiredShareCount(2) .setTotalShareCount(3) .setPrime(7) .build(); rxShamir .createShares(FIVE, creationScheme) .test() .awaitDone(200, MILLISECONDS) .assertNoErrors() .assertComplete(); }
@Test public void testCreateShares_secretEqualToPrime() { final CreationScheme creationScheme = CreationScheme .builder() .setRequiredShareCount(2) .setTotalShareCount(3) .setPrime(5) .build(); rxShamir .createShares(FIVE, creationScheme) .test() .awaitDone(200, MILLISECONDS) .assertError(IllegalStateException.class) .assertNotComplete(); }
@Test public void testCreateShares_secretGreaterThanPrime() { final CreationScheme creationScheme = CreationScheme .builder() .setRequiredShareCount(2) .setTotalShareCount(3) .setPrime(5) .build(); rxShamir .createShares(SEVEN, creationScheme) .test() .awaitDone(200, MILLISECONDS) .assertError(IllegalStateException.class) .assertNotComplete(); }