1 /* 2 * Copyright (c) 2011 Google, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.common.truth; 17 18 import static com.google.common.base.Preconditions.checkNotNull; 19 20 import org.jspecify.annotations.Nullable; 21 22 /** 23 * In a fluent assertion chain, exposes the most common {@code that} method, which accepts a value 24 * under test and returns a {@link Subject}. 25 * 26 * <p>For more information about the methods in this class, see <a 27 * href="https://truth.dev/faq#full-chain">this FAQ entry</a>. 28 * 29 * <h3>For people extending Truth</h3> 30 * 31 * <p>You won't extend this type. When you write a custom subject, see <a 32 * href="https://truth.dev/extension">our doc on extensions</a>. 33 */ 34 public final class SimpleSubjectBuilder<SubjectT extends Subject, ActualT> { 35 private final FailureMetadata metadata; 36 private final Subject.Factory<SubjectT, ActualT> subjectFactory; 37 SimpleSubjectBuilder( FailureMetadata metadata, Subject.Factory<SubjectT, ActualT> subjectFactory)38 SimpleSubjectBuilder( 39 FailureMetadata metadata, Subject.Factory<SubjectT, ActualT> subjectFactory) { 40 this.metadata = checkNotNull(metadata); 41 this.subjectFactory = checkNotNull(subjectFactory); 42 } 43 that(@ullable ActualT actual)44 public SubjectT that(@Nullable ActualT actual) { 45 return subjectFactory.createSubject(metadata, actual); 46 } 47 48 } 49