コード例 #1
0
  public void test_getClass() {
    Integer i = new Integer(10);
    Class cls = i.getClass();
    if (cls == null) harness.fail("Object.getClass: Error: test_getClass returned null");

    ObjectTest obj = new ObjectTest();
    if (obj.getClass() != getClass())
      harness.fail("Object.getClass: Error: test_getClass returned wrong class");
  }
コード例 #2
0
  public void test_hashCode() {
    Object s = this;
    if (s.hashCode() != hashCode())
      harness.fail("Object.hashCode: Error: test_hashCode returned wrong results - 1");

    int hash = s.hashCode();

    if (hash != s.hashCode())
      harness.fail("Object.hashCode: Error: test_hashCode returned wrong results - 2");
  }
コード例 #3
0
  public void test_equals() {
    Object nu = this;

    // reflexive
    if (this != nu) harness.fail("Object.equals: Error: test_equals returned wrong results - 1");
    if (!this.equals(nu))
      harness.fail("Object.equals: Error: test_equals returned wrong results - 2");

    if (!nu.equals(nu))
      harness.fail("Object.equals: Error: test_equals returned wrong results - 3");

    // symmetric
    Object nu1 = nu;

    if (!(nu.equals(nu1) && nu1.equals(nu)))
      harness.fail("Object.equals: Error: test_equals returned wrong results - 4");

    // transitive
    if (!(nu.equals(nu1) && nu1.equals(this) && equals(nu)))
      harness.fail("Object.equals: Error: test_equals returned wrong results - 5");

    Object p = null;
    if (equals(p)) harness.fail("Object.equals: Error: test_equals returned wrong results - 6");
  }
コード例 #4
0
 public void test_toString() {
   if (toString() == null)
     harness.fail("Object.toString: Error: test_toString returned null string");
   if (!toString().equals(getClass().getName() + "@" + Integer.toHexString(hashCode())))
     harness.fail("Object.toString: Error: test_toString returned wrong string");
 }