/*
 * Copyright 2015 West Coast Informatics, LLC
 */
package org.ihtsdo.otf.ts.helpers;

import org.apache.log4j.Logger;

/**
 * Automates JUnit testing of equals and hashcode methods.
 */
public class CopyConstructorTester extends ProxyTester {

  /**
   * Constructs a new getter/setter tester to test objects of a particular
   * class.
   * 
   * @param obj Object to test.
   */
  public CopyConstructorTester(Object obj) {
    super(obj);
  }

  /**
   * Creates an object from the object.
   *
   * @param interfaceType the interface type
   * @return true, if successful
   * @throws Exception the exception
   */
  public boolean testCopyConstructor(Class<?> interfaceType) throws Exception {
    Logger.getLogger(getClass()).debug(
        "Test copy constructor - " + clazz.getName());
    Object o1 = createObject(1);
    Object o2 = clazz.getConstructor(new Class<?>[] {
      interfaceType
    }).newInstance(new Object[] {
      o1
    });
    Logger.getLogger(getClass()).debug(
        "    " + o1.toString() + " = " + o2.toString());
    return o1.equals(o2) && o1.hashCode() == o2.hashCode()
        && o1.toString().equals(o2.toString());
  }

  /**
   * Creates an object from the object.
   * @param interfaceType the interface type
   * @return true, if successful
   * @throws Exception the exception
   */
  public boolean testCopyConstructorCascadeDeep(Class<?> interfaceType)
    throws Exception {
    Logger.getLogger(getClass()).info(
        "Test copy constructor - " + clazz.getName());
    Object o1 = createObject(1);
    Object o2 = clazz.getConstructor(new Class<?>[] {
        interfaceType, boolean.class, boolean.class
    }).newInstance(new Object[] {
        o1, false, false
    });
    Logger.getLogger(getClass()).info(
        "    " + o1.toString() + " = " + o2.toString());
    return o1.equals(o2) && o1.hashCode() == o2.hashCode()
        && o1.toString().equals(o2.toString());
  }

}

@@ -1927,10 +1927,749 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Test copy constructor deep.%0A   *%0A   * @param interfaceType the interface type%0A   * @return true, if successful%0A   * @throws Exception the exception%0A   */%0A  public boolean testCopyConstructorDeep(Class%3C?%3E interfaceType)%0A    throws Exception %7B%0A    Logger.getLogger(getClass()).info(%0A        %22Test copy constructor - %22 + clazz.getName());%0A    Object o1 = createObject(1);%0A    Object o2 = clazz.getConstructor(new Class%3C?%3E%5B%5D %7B%0A        interfaceType, boolean.class%0A    %7D).newInstance(new Object%5B%5D %7B%0A        o1, false%0A    %7D);%0A    Logger.getLogger(getClass()).info(%0A        %22    %22 + o1.toString() + %22 = %22 + o2.toString());%0A    return o1.equals(o2) && o1.hashCode() == o2.hashCode()%0A        && o1.toString().equals(o2.toString());%0A  %7D%0A%0A
 %7D%0A

copy constructor improvement.