1 /** 2 * Copyright 2006-2017 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.objenesis.tck.android; 17 18 import java.io.ByteArrayOutputStream; 19 import java.io.PrintStream; 20 import java.util.Map; 21 22 import org.objenesis.ObjenesisSerializer; 23 import org.objenesis.ObjenesisStd; 24 import org.objenesis.tck.Main; 25 import org.objenesis.tck.Reporter; 26 27 import android.test.AndroidTestCase; 28 import android.test.suitebuilder.annotation.SmallTest; 29 30 /** 31 * Test case running the entire tck on android. 32 * 33 * @author Henri Tremblay 34 */ 35 public class ObjenesisTest extends AndroidTestCase { 36 37 public static class JUnitReporter implements Reporter { 38 39 private String currentObjenesis; 40 41 private String currentCandidate; 42 43 public void startTests(String platformDescription, Map<String, Object> allCandidates, 44 Map<String, Object> allInstantiators) { 45 } 46 47 public void startTest(String candidateDescription, String objenesisDescription) { 48 currentCandidate = candidateDescription; 49 currentObjenesis = objenesisDescription; 50 } 51 52 public void endObjenesis(String description) { 53 } 54 55 public void endTests() { 56 } 57 58 public void exception(Exception exception) { 59 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 60 PrintStream out = new PrintStream(buffer); 61 out.println("Exception when instantiating " + currentCandidate + " with " 62 + currentObjenesis + ": "); 63 exception.printStackTrace(out); 64 fail(buffer.toString()); 65 } 66 67 public void result(boolean instantiatedObject) { 68 assertTrue("Instantiating " + currentCandidate + " with " + currentObjenesis + " failed", 69 instantiatedObject); 70 } 71 72 public void endTest() { 73 } 74 } 75 76 @SmallTest 77 public void testObjenesisStd() throws Exception { 78 Main.runStandardTest(new ObjenesisStd(), new JUnitReporter()); 79 } 80 81 @SmallTest 82 public void testObjenesisSerializer() throws Exception { 83 Main.runSerializerTest(new ObjenesisSerializer(), new JUnitReporter()); 84 } 85 86 @SmallTest 87 public void testObjenesisSerializerParentConstructorCalled() throws Exception { 88 boolean result = Main.runParentConstructorTest(new ObjenesisSerializer()); 89 assertTrue(result); 90 } 91 92 }