public void testGet_misc() { assertNotNull(ArbitraryInstances.get(CharMatcher.class)); assertNotNull(ArbitraryInstances.get(Currency.class).getCurrencyCode()); assertNotNull(ArbitraryInstances.get(Locale.class)); ArbitraryInstances.get(Joiner.class).join(ImmutableList.of("a")); ArbitraryInstances.get(Splitter.class).split("a,b"); assertFalse(ArbitraryInstances.get(Optional.class).isPresent()); ArbitraryInstances.get(Stopwatch.class).start(); assertNotNull(ArbitraryInstances.get(Ticker.class)); assertNotNull(ArbitraryInstances.get(MapConstraint.class)); assertFreshInstanceReturned(Random.class); assertEquals(ArbitraryInstances.get(Random.class).nextInt(), ArbitraryInstances.get(Random.class).nextInt()); }
/** * Add a constraint that verifies that neither the key nor the value is * null. If either is null, a {@link NullPointerException} is thrown. * * @return */ @SuppressWarnings("unchecked") public Mapper<K, V> keyAndValueNotNull() { return addConstraint((MapConstraint<K, V>) MapConstraints.notNull()); }
/** * Add a constraint that verifies that the key is * null. If is null, a {@link NullPointerException} is thrown. * * @return */ @SuppressWarnings("unchecked") public Mapper<K, V> keyNotNull() { return addConstraint((MapConstraint<K, V>) KeyNotNullRestraint.INSTANCE); }
/** * Add a constraint that verifies that the value is * null. If is null, a {@link NullPointerException} is thrown. * * @return */ @SuppressWarnings("unchecked") public Mapper<K, V> valueNotNull() { return addConstraint((MapConstraint<K, V>) ValueNotNullRestraint.INSTANCE); }
/** * Add a constrained view of the delegate map, using the specified constraint * * @param constraint * @return */ private Mapper<K, V> addConstraint(MapConstraint<K, V> constraint) { this.delegate = Optional.of(MapConstraints.constrainedMap(delegate.get(), constraint)); return this; }