Shape implements FromSourceLocation, Tagged, ToShapeId, Comparable<Shape> { public final <T extends Trait> T expectTrait(Class<T> traitClass) { return getTrait(traitClass).orElseThrow(() -> new ExpectationNotMetException(String.format( "Expected shape `%s` to have a trait `%s`", getId(), traitClass.getCanonicalName()), this)); } @SuppressWarnings("unchecked")  Shape(AbstractShapeBuilder builder, boolean expectMemberSegments); @SuppressWarnings("unchecked") static B shapeToBuilder(S shape); final ShapeType getType(); abstract R accept(ShapeVisitor<R> cases); final ShapeId getId(); boolean hasTrait(String id); boolean hasTrait(ShapeId id); boolean hasTrait(Class<? extends Trait> traitClass); Optional<Trait> findTrait(ShapeId id); Optional<Trait> findTrait(String id); @SuppressWarnings("unchecked") final Optional<T> getTrait(Class<T> traitClass); final T expectTrait(Class<T> traitClass); final Map<ShapeId, Trait> getAllTraits(); Optional<T> getMemberTrait(Model model, Class<T> trait); Optional<Trait> findMemberTrait(Model model, String traitName); Optional<BigDecimalShape> asBigDecimalShape(); Optional<BigIntegerShape> asBigIntegerShape(); Optional<BlobShape> asBlobShape(); Optional<BooleanShape> asBooleanShape(); Optional<ByteShape> asByteShape(); Optional<ShortShape> asShortShape(); Optional<FloatShape> asFloatShape(); Optional<DocumentShape> asDocumentShape(); Optional<DoubleShape> asDoubleShape(); Optional<IntegerShape> asIntegerShape(); Optional<ListShape> asListShape(); Optional<SetShape> asSetShape(); Optional<LongShape> asLongShape(); Optional<MapShape> asMapShape(); Optional<MemberShape> asMemberShape(); Optional<OperationShape> asOperationShape(); Optional<ResourceShape> asResourceShape(); Optional<ServiceShape> asServiceShape(); Optional<StringShape> asStringShape(); Optional<StructureShape> asStructureShape(); Optional<UnionShape> asUnionShape(); Optional<TimestampShape> asTimestampShape(); final boolean isBigDecimalShape(); final boolean isBigIntegerShape(); final boolean isBlobShape(); final boolean isBooleanShape(); final boolean isByteShape(); final boolean isShortShape(); final boolean isFloatShape(); final boolean isDocumentShape(); final boolean isDoubleShape(); final boolean isListShape(); final boolean isSetShape(); final boolean isIntegerShape(); final boolean isLongShape(); final boolean isMapShape(); final boolean isMemberShape(); final boolean isOperationShape(); final boolean isResourceShape(); final boolean isServiceShape(); final boolean isStringShape(); final boolean isStructureShape(); final boolean isUnionShape(); final boolean isTimestampShape(); Collection<MemberShape> members(); @Override ShapeId toShapeId(); @Override final List<String> getTags(); @Override final SourceLocation getSourceLocation(); @Override int compareTo(Shape other); @Override final String toString(); @Override int hashCode(); @Override boolean equals(Object o);  }
@Test public void throwsWhenTraitNotFound() { Shape string = StringShape.builder().id("com.foo#example").build(); Assertions.assertThrows(ExpectationNotMetException.class, () -> string.expectTrait(DeprecatedTrait.class)); }