Makes tests to be runnable both on JVM and TeaVM

This commit is contained in:
konsoletyper 2013-12-03 22:38:22 +04:00
parent d3063e7811
commit 59615f3165
6 changed files with 21 additions and 18 deletions

View File

@ -7,7 +7,7 @@ import org.junit.Test;
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
class TClassTests { public class ClassTests {
@Test @Test
public void classNameEvaluated() { public void classNameEvaluated() {
assertEquals("java.lang.Object", Object.class.getName()); assertEquals("java.lang.Object", Object.class.getName());

View File

@ -7,7 +7,7 @@ import org.junit.Test;
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
class TObjectTests { public class ObjectTests {
@Test @Test
public void objectCreated() { public void objectCreated() {
Object a = new Object(); Object a = new Object();

View File

@ -7,30 +7,30 @@ import org.junit.Test;
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
class TStringBuilderTests { public class StringBuilderTests {
public void integerAppended() { public void integerAppended() {
TStringBuilder sb = new TStringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(23); sb.append(23);
assertEquals("23", sb.toString()); assertEquals("23", sb.toString());
} }
@Test @Test
public void largeIntegerAppended() { public void largeIntegerAppended() {
TStringBuilder sb = new TStringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(123456); sb.append(123456);
assertEquals("123456", sb.toString()); assertEquals("123456", sb.toString());
} }
@Test @Test
public void negativeIntegerAppended() { public void negativeIntegerAppended() {
TStringBuilder sb = new TStringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(-23); sb.append(-23);
assertEquals("-23", sb.toString()); assertEquals("-23", sb.toString());
} }
@Test @Test
public void maxIntegerAppended() { public void maxIntegerAppended() {
TStringBuilder sb = new TStringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(2147483647); sb.append(2147483647);
assertEquals("2147483647", sb.toString()); assertEquals("2147483647", sb.toString());
} }

View File

@ -7,7 +7,7 @@ import org.junit.Test;
* *
* @author Alexey Andreev <konsoletyper@gmail.com> * @author Alexey Andreev <konsoletyper@gmail.com>
*/ */
class TStringTests { public class StringTests {
@Test @Test
public void charsExtracted() { public void charsExtracted() {
String str = "123"; String str = "123";

View File

@ -7,14 +7,14 @@ import org.junit.Test;
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
class TSystemTests { public class SystemTests {
@Test @Test
public void copiesArray() { public void copiesArray() {
TObject a = new TObject(); Object a = new Object();
TObject b = new TObject(); Object b = new Object();
TObject[] src = { a, b, a }; Object[] src = { a, b, a };
TObject[] dest = new TObject[3]; Object[] dest = new Object[3];
TSystem.arraycopy(TObject.wrap(src), 0, TObject.wrap(dest), 0, 3); System.arraycopy(src, 0, dest, 0, 3);
assertSame(a, dest[0]); assertSame(a, dest[0]);
assertSame(b, dest[1]); assertSame(b, dest[1]);
assertSame(a, dest[2]); assertSame(a, dest[2]);
@ -22,21 +22,21 @@ class TSystemTests {
@Test(expected = IndexOutOfBoundsException.class) @Test(expected = IndexOutOfBoundsException.class)
public void failsToCopyArraysWithInvalidIndexes() { public void failsToCopyArraysWithInvalidIndexes() {
TSystem.arraycopy(TObject.wrap(new TObject[0]), 0, TObject.wrap(new TObject[0]), 0, 1); System.arraycopy(new Object[0], 0, new TObject[0], 0, 1);
} }
@Test(expected = ArrayStoreException.class) @Test(expected = ArrayStoreException.class)
public void failsToCopyArraysWithIncompatibleElements() { public void failsToCopyArraysWithIncompatibleElements() {
TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, TObject.wrap(new int[1]), 0, 1); System.arraycopy(new Object[1], 0, new int[1], 0, 1);
} }
@Test(expected = NullPointerException.class) @Test(expected = NullPointerException.class)
public void failsToCopyFromNullSource() { public void failsToCopyFromNullSource() {
TSystem.arraycopy(null, 0, TObject.wrap(new int[1]), 0, 1); System.arraycopy(null, 0, new int[1], 0, 1);
} }
@Test(expected = NullPointerException.class) @Test(expected = NullPointerException.class)
public void failsToCopyToNullTarget() { public void failsToCopyToNullTarget() {
TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, null, 0, 1); System.arraycopy(new TObject[1], 0, null, 0, 1);
} }
} }

View File

@ -46,6 +46,9 @@ public class ClasslibTestGenerator {
writer = new SourceWriter(naming); writer = new SourceWriter(naming);
renderer = new Renderer(writer, classSource); renderer = new Renderer(writer, classSource);
DependencyChecker dependencyChecker = new DependencyChecker(classSource); DependencyChecker dependencyChecker = new DependencyChecker(classSource);
for (int i = 0; i < testClasses.length; ++i) {
testClasses[i] = "org.teavm.classlib." + testClasses[i];
}
for (String testClass : testClasses) { for (String testClass : testClasses) {
ClassHolder classHolder = classSource.getClassHolder(testClass); ClassHolder classHolder = classSource.getClassHolder(testClass);
findTests(classHolder); findTests(classHolder);