BundleCondition extends BasicCondition<Bundle, BundleCondition> implements BundleChecks<BundleCondition> { @NonNull @Override public BundleCondition valueIsOfType(@NonNull String key, @NonNull Class<?> type) { require(subject).containsKey(key); Object intermediateSubject = subject.get(key); check(intermediateSubject).isNotNull(); if (!type.isAssignableFrom(intermediateSubject.getClass())) { DbcAssertionError.throwNew(new IllegalStateException("Expected bundle to contain value of type <" + type + "> with key <" + key + ">"), this.message); } return result(); } BundleCondition(Bundle subject); @NonNull @Override BundleCondition containsKey(@NonNull String key); @NonNull @Override BundleCondition valueIsOfType(@NonNull String key, @NonNull Class<?> type);  }
@Test public void valueIsOfType() throws Exception { Bundle subject = new Bundle(); subject.putString("KEY", "VALUE"); BundleCondition condition = new BundleCondition(subject); condition.valueIsOfType("KEY", String.class); Assertions.assertThatThrownBy(() -> condition.valueIsOfType("KEY", Integer.class)) .isInstanceOf(DbcAssertionError.class) .hasCauseInstanceOf(IllegalStateException.class); }