package org.plumelib.reflection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.Test;

/** Test code for the ReflectionPlume class. */
@SuppressWarnings({
  "UseCorrectAssertInTests" // I don't see the problem with using `assert`
})
public final class TestReflectionPlume {

  static class Inner {
    static class InnerInner {}
  }

  @Test
  public void test_classForName() {
    try {
      assert ReflectionPlume.classForName("int").equals(int.class);
      assert ReflectionPlume.classForName("boolean").equals(boolean.class);
      assert ReflectionPlume.classForName("java.lang.Class").equals(Class.class);
      assert ReflectionPlume.classForName("java.util.Map.Entry").equals(java.util.Map.Entry.class);
      assert ReflectionPlume.classForName("java.util.Map$Entry").equals(java.util.Map.Entry.class);
      assert ReflectionPlume.classForName(
              "org.plumelib.reflection.TestReflectionPlume.Inner.InnerInner")
          .equals(Inner.InnerInner.class);
      assert ReflectionPlume.classForName(
              "org.plumelib.reflection.TestReflectionPlume.Inner$InnerInner")
          .equals(Inner.InnerInner.class);
      assert ReflectionPlume.classForName(
              "org.plumelib.reflection.TestReflectionPlume$Inner.InnerInner")
          .equals(Inner.InnerInner.class);
      assert ReflectionPlume.classForName(
              "org.plumelib.reflection.TestReflectionPlume$Inner$InnerInner")
          .equals(Inner.InnerInner.class);
    } catch (ClassNotFoundException e) {
      throw new Error(e);
    }
  }

  @Test
  public void test_fullyQualifiedNameToSimpleName() {
    assert ReflectionPlume.fullyQualifiedNameToSimpleName("java.lang.String").equals("String");
    assert ReflectionPlume.fullyQualifiedNameToSimpleName("String").equals("String");
  }

  @Test
  public void test_isSubtype() {
    // private boolean isSubtype(Class<?> sub, Class<?> sup) {
    assert ReflectionPlume.isSubtype(Integer.class, Integer.class);
    assert ReflectionPlume.isSubtype(Cloneable.class, Cloneable.class);
    assert ReflectionPlume.isSubtype(Object.class, Object.class);
    assert ReflectionPlume.isSubtype(Integer.class, Number.class);
    assert !ReflectionPlume.isSubtype(Number.class, Integer.class);
    assert ReflectionPlume.isSubtype(Integer.class, Comparable.class);
    assert !ReflectionPlume.isSubtype(Comparable.class, Integer.class);
    assert ReflectionPlume.isSubtype(Integer.class, Object.class);
    assert !ReflectionPlume.isSubtype(Object.class, Integer.class);
    assert !ReflectionPlume.isSubtype(Integer.class, Float.class);
    assert ReflectionPlume.isSubtype(Collection.class, Iterable.class);
    assert !ReflectionPlume.isSubtype(Iterable.class, Collection.class);
    assert ReflectionPlume.isSubtype(ArrayList.class, Iterable.class);
    assert !ReflectionPlume.isSubtype(Iterable.class, ArrayList.class);
    assert ReflectionPlume.isSubtype(ArrayList.class, Cloneable.class);
    assert !ReflectionPlume.isSubtype(Cloneable.class, ArrayList.class);
    assert ReflectionPlume.isSubtype(ArrayList.class, List.class);
    assert !ReflectionPlume.isSubtype(List.class, ArrayList.class);
  }

  @Test
  public void test_methodForName() {
    // public static Method methodForName(String methodname) throws ClassNotFoundException
    //
    // Just test that the method is found (return value is non-null and non-erroneous).
    try {
      assert null
          != ReflectionPlume.methodForName(
              "org.plumelib.reflection.ReflectionPlume.methodForName(java.lang.String, java.lang.String, java.lang.Class[])");
      assert null
          != ReflectionPlume.methodForName(
              "org.plumelib.reflection.ReflectionPlume.methodForName(java.lang.String,java.lang.String,java.lang.Class[])");
      assert null != ReflectionPlume.methodForName("java.lang.Math.min(int,int)");
    } catch (Exception e) {
      e.printStackTrace();
      throw new Error(e);
    }
    try {
      java.lang.reflect.Method m =
          ReflectionPlume.methodForName("org.plumelib.reflection.ReflectionPlume.methodForName()");
      throw new Error("Didn't throw NoSuchMethodException");
    } catch (NoSuchMethodException e) {
      // nothing to do; this is the expected case
    } catch (Exception e) {
      e.printStackTrace();
      throw new Error(e);
    }
  }
}

@@ -480,24 +480,20 @@
 e(%22int%22)
-.equals(
+ == 
 int.clas
@@ -489,25 +489,24 @@
 == int.class
-)
 ;%0A      asse
@@ -547,24 +547,20 @@
 oolean%22)
-.equals(
+ == 
 boolean.
@@ -560,25 +560,24 @@
 oolean.class
-)
 ;%0A      asse
@@ -626,24 +626,20 @@
 .Class%22)
-.equals(
+ == 
 Class.cl
@@ -637,25 +637,24 @@
  Class.class
-)
 ;%0A      asse
@@ -703,32 +703,28 @@
 .Map.Entry%22)
-.equals(
+ == 
 java.util.Ma
@@ -728,33 +728,32 @@
 .Map.Entry.class
-)
 ;%0A      assert R
@@ -802,24 +802,20 @@
 $Entry%22)
-.equals(
+ == 
 java.uti
@@ -827,25 +827,24 @@
 .Entry.class
-)
 ;%0A      asse
@@ -960,32 +960,27 @@
 )%0A          
-.equals(
+== 
 Inner.InnerI
@@ -981,33 +981,32 @@
 InnerInner.class
-)
 ;%0A      assert R
@@ -1118,32 +1118,27 @@
 )%0A          
-.equals(
+== 
 Inner.InnerI
@@ -1139,33 +1139,32 @@
 InnerInner.class
-)
 ;%0A      assert R
@@ -1276,32 +1276,27 @@
 )%0A          
-.equals(
+== 
 Inner.InnerI
@@ -1301,25 +1301,24 @@
 rInner.class
-)
 ;%0A      asse
@@ -1438,24 +1438,19 @@
         
-.equals(
+== 
 Inner.In
@@ -1459,25 +1459,24 @@
 rInner.class
-)
 ;%0A    %7D catc

Use == rather than .equals