/*
 * Copyright (c) 2015 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.common.truth.extension;

import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;

import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
 * A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}.
 *
 * @author Kurt Alfred Kluever (kak@google.com)
 */
public final class EmployeeSubject extends Subject {

  // User-defined entry point
  public static EmployeeSubject assertThat(@Nullable Employee employee) {
    return assertAbout(EMPLOYEE_SUBJECT_FACTORY).that(employee);
  }

  // Static method for getting the subject factory (for use with assertAbout())
  public static Subject.Factory<EmployeeSubject, Employee> employees() {
    return EMPLOYEE_SUBJECT_FACTORY;
  }

  // Boiler-plate Subject.Factory for EmployeeSubject
  private static final Subject.Factory<EmployeeSubject, Employee> EMPLOYEE_SUBJECT_FACTORY =
      EmployeeSubject::new;

  private final Employee actual;

  private EmployeeSubject(FailureMetadata failureMetadata, @Nullable Employee subject) {
    super(failureMetadata, subject);
    this.actual = subject;
  }

  // User-defined test assertion SPI below this point

  public void hasName(String name) {
    check("name()").that(actual.name()).isEqualTo(name);
  }

  public void hasUsername(String username) {
    check("username()").that(actual.username()).isEqualTo(username);
  }

  public void hasId(long id) {
    check("id()").that(actual.id()).isEqualTo(id);
  }

  public void hasLocation(Employee.Location location) {
    check("location()").that(actual.location()).isEqualTo(location);
  }

  public void isCeo() {
    if (!actual.isCeo()) {
      failWithActual(simpleFact("expected to be CEO"));
    }
  }

  public void isNotCeo() {
    if (actual.isCeo()) {
      failWithActual(simpleFact("expected not to be CEO"));
    }
  }

  // TODO(kak): Add methods that return other subjects. E.g.,
  // public StringSubject username() {}
  // public IterableSubject languages() {}
}

@@ -777,31 +777,171 @@
 n.truth.
-FailureMetadata
+ComparableSubject;%0Aimport com.google.common.truth.FailureMetadata;%0Aimport com.google.common.truth.LongSubject;%0Aimport com.google.common.truth.StringSubject
 ;%0Aimport
@@ -2072,42 +2072,13 @@
     
-check(%22name()%22).that(actual.name()
+name(
 ).is
@@ -2146,23 +2146,16 @@
 ) %7B%0A    
-check(%22
 username
@@ -2160,34 +2160,8 @@
 me()
-%22).that(actual.username())
 .isE
@@ -2222,38 +2222,11 @@
     
-check(%22id()%22).that(actual.id()
+id(
 ).is
@@ -2307,15 +2307,8 @@
     
-check(%22
 loca
@@ -2317,34 +2317,8 @@
 on()
-%22).that(actual.location())
 .isE
@@ -2591,69 +2591,137 @@
  // 
-TODO(kak): Add methods that return other subjects. E.g.,%0A  //
+Chained subjects methods below this point%0A%0A  public StringSubject name() %7B%0A    return check(%22name()%22).that(actual.name());%0A  %7D%0A%0A 
  pub
@@ -2754,51 +2754,264 @@
 () %7B
-%7D
 %0A  
-// public IterableSubject languages() %7B
+  return check(%22username()%22).that(actual.username());%0A  %7D%0A%0A  public LongSubject id() %7B%0A    return check(%22id()%22).that(actual.id());%0A  %7D%0A%0A  public ComparableSubject%3CEmployee.Location%3E location() %7B%0A    return check(%22location()%22).that(actual.location());%0A  
 %7D%0A%7D%0A

Add missing chained subject methods in EmployeeSubject