|
| 1 | +package testsuite.core |
| 2 | + |
| 3 | +import testsuite.Assert.ok |
| 4 | +import testsuite.Assert |
| 5 | + |
| 6 | +object ClassOfTest { |
| 7 | + def main(): Unit = { |
| 8 | + testGetName() |
| 9 | + testUniqueness() |
| 10 | + testIsPrimitive() |
| 11 | + testIsInterface() |
| 12 | + testIsArray() |
| 13 | + testGetComponentType() |
| 14 | + } |
| 15 | + |
| 16 | + def testGetName(): Unit = { |
| 17 | + Assert.assertSame("java.lang.String", classOf[String].getName()) |
| 18 | + Assert.assertSame("java.lang.StringBuilder", classOf[java.lang.StringBuilder].getName()) |
| 19 | + Assert.assertSame("int", classOf[Int].getName()) |
| 20 | + Assert.assertSame("void", classOf[Unit].getName()) |
| 21 | + |
| 22 | + Assert.assertSame("[Ljava.lang.Object;", classOf[Array[AnyRef]].getName()) |
| 23 | + Assert.assertSame("[Ljava.lang.String;", classOf[Array[String]].getName()) |
| 24 | + Assert.assertSame("[[Ljava.lang.CharSequence;", classOf[Array[Array[CharSequence]]].getName()) |
| 25 | + |
| 26 | + Assert.assertSame("[Z", classOf[Array[Boolean]].getName()) |
| 27 | + Assert.assertSame("[C", classOf[Array[Char]].getName()) |
| 28 | + Assert.assertSame("[B", classOf[Array[Byte]].getName()) |
| 29 | + Assert.assertSame("[S", classOf[Array[Short]].getName()) |
| 30 | + Assert.assertSame("[I", classOf[Array[Int]].getName()) |
| 31 | + Assert.assertSame("[J", classOf[Array[Long]].getName()) |
| 32 | + Assert.assertSame("[F", classOf[Array[Float]].getName()) |
| 33 | + Assert.assertSame("[D", classOf[Array[Double]].getName()) |
| 34 | + } |
| 35 | + |
| 36 | + def testUniqueness(): Unit = { |
| 37 | + Assert.assertSame(classOf[String], classOf[String]) |
| 38 | + Assert.assertSame(classOf[java.lang.StringBuilder], classOf[java.lang.StringBuilder]) |
| 39 | + Assert.assertSame(classOf[CharSequence], classOf[CharSequence]) |
| 40 | + Assert.assertSame(classOf[Int], classOf[Int]) |
| 41 | + |
| 42 | + Assert.assertSame(classOf[Array[Int]], classOf[Array[Int]]) |
| 43 | + Assert.assertSame(classOf[Array[Array[java.lang.Byte]]], classOf[Array[Array[java.lang.Byte]]]) |
| 44 | + Assert.assertSame(classOf[Array[Array[Int]]], classOf[Array[Array[Int]]]) |
| 45 | + } |
| 46 | + |
| 47 | + def testIsPrimitive(): Unit = { |
| 48 | + Assert.assertSame(false, classOf[AnyRef].isPrimitive()) |
| 49 | + Assert.assertSame(false, classOf[String].isPrimitive()) |
| 50 | + Assert.assertSame(false, classOf[CharSequence].isPrimitive()) |
| 51 | + Assert.assertSame(false, classOf[java.lang.Iterable[Any]].isPrimitive()) |
| 52 | + Assert.assertSame(false, classOf[Array[Int]].isPrimitive()) |
| 53 | + Assert.assertSame(false, classOf[Array[String]].isPrimitive()) |
| 54 | + Assert.assertSame(false, classOf[Array[CharSequence]].isPrimitive()) |
| 55 | + |
| 56 | + Assert.assertSame(true, classOf[Int].isPrimitive()) |
| 57 | + Assert.assertSame(true, classOf[Unit].isPrimitive()) |
| 58 | + } |
| 59 | + |
| 60 | + def testIsInterface(): Unit = { |
| 61 | + Assert.assertSame(false, classOf[AnyRef].isInterface()) |
| 62 | + Assert.assertSame(false, classOf[String].isInterface()) |
| 63 | + Assert.assertSame(false, classOf[Int].isInterface()) |
| 64 | + Assert.assertSame(false, classOf[Array[Int]].isInterface()) |
| 65 | + Assert.assertSame(false, classOf[Array[String]].isInterface()) |
| 66 | + Assert.assertSame(false, classOf[Array[CharSequence]].isInterface()) |
| 67 | + |
| 68 | + Assert.assertSame(true, classOf[CharSequence].isInterface()) |
| 69 | + Assert.assertSame(true, classOf[java.lang.Iterable[Any]].isInterface()) |
| 70 | + } |
| 71 | + |
| 72 | + def testIsArray(): Unit = { |
| 73 | + Assert.assertSame(false, classOf[AnyRef].isArray()) |
| 74 | + Assert.assertSame(false, classOf[String].isArray()) |
| 75 | + Assert.assertSame(false, classOf[Int].isArray()) |
| 76 | + Assert.assertSame(false, classOf[CharSequence].isArray()) |
| 77 | + Assert.assertSame(false, classOf[java.lang.Iterable[Any]].isArray()) |
| 78 | + |
| 79 | + Assert.assertSame(true, classOf[Array[Int]].isArray()) |
| 80 | + Assert.assertSame(true, classOf[Array[String]].isArray()) |
| 81 | + Assert.assertSame(true, classOf[Array[CharSequence]].isArray()) |
| 82 | + } |
| 83 | + |
| 84 | + def testGetComponentType(): Unit = { |
| 85 | + Assert.assertSame(null, classOf[AnyRef].getComponentType()) |
| 86 | + Assert.assertSame(null, classOf[String].getComponentType()) |
| 87 | + Assert.assertSame(null, classOf[Int].getComponentType()) |
| 88 | + Assert.assertSame(null, classOf[CharSequence].getComponentType()) |
| 89 | + Assert.assertSame(null, classOf[java.lang.Iterable[Any]].getComponentType()) |
| 90 | + |
| 91 | + Assert.assertSame(classOf[Int], classOf[Array[Int]].getComponentType()) |
| 92 | + Assert.assertSame(classOf[String], classOf[Array[String]].getComponentType()) |
| 93 | + Assert.assertSame(classOf[AnyRef], classOf[Array[AnyRef]].getComponentType()) |
| 94 | + |
| 95 | + Assert.assertSame( |
| 96 | + classOf[Array[CharSequence]], |
| 97 | + classOf[Array[Array[CharSequence]]].getComponentType() |
| 98 | + ) |
| 99 | + |
| 100 | + Assert.assertSame( |
| 101 | + classOf[Array[Long]], |
| 102 | + classOf[Array[Array[Long]]].getComponentType() |
| 103 | + ) |
| 104 | + |
| 105 | + Assert.assertSame( |
| 106 | + classOf[Array[Array[java.lang.Byte]]], |
| 107 | + classOf[Array[Array[Array[java.lang.Byte]]]].getComponentType() |
| 108 | + ) |
| 109 | + |
| 110 | + Assert.assertSame( |
| 111 | + classOf[Array[ClassForUniqueGetComponentTypeTest]].getComponentType(), |
| 112 | + classOf[Array[ClassForUniqueGetComponentTypeTest]].getComponentType() |
| 113 | + ) |
| 114 | + } |
| 115 | + |
| 116 | + class ClassForUniqueGetComponentTypeTest |
| 117 | +} |
0 commit comments