1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html#License
3/*
4 *******************************************************************************
5 * Copyright (C) 2005-2016, International Business Machines Corporation and         *
6 * others. All Rights Reserved.                                                *
7 *******************************************************************************
8 */
9package com.ibm.icu.dev.test.serializable;
10
11import java.io.IOException;
12import java.lang.reflect.Modifier;
13import java.util.List;
14
15import org.junit.Test;
16import org.junit.runner.RunWith;
17
18import com.ibm.icu.dev.test.TestFmwk;
19import com.ibm.icu.dev.test.serializable.SerializableTestUtility.Handler;
20
21import junitparams.JUnitParamsRunner;
22import junitparams.Parameters;
23
24/**
25 * @author sgill
26 * @author emader
27 *
28 */
29@RunWith(JUnitParamsRunner.class)
30public class CoverageTest extends TestFmwk {
31
32    @Test
33    @Parameters(method="generateClassList")
34    public void testSerialization(String className) throws ClassNotFoundException, IOException {
35        Class c = Class.forName(className);
36        int m = c.getModifiers();
37
38        Handler classHandler = SerializableTestUtility.getHandler(className);
39        if (classHandler == null) {
40            if (!Modifier.isAbstract(m)) {
41                errln("Missing test handler. Update the list of tests in SerializableTest.java to include a test case for " + className);
42            }
43            return;
44        }
45        Object[] testObjects = classHandler.getTestObjects();
46        byte[] serializedBytes = SerializableTestUtility.getSerializedBytes(testObjects);
47        Object[] serializedObjects = SerializableTestUtility.getSerializedObjects(serializedBytes);
48        for (int i = 0; i < testObjects.length; i++) {
49            if (!classHandler.hasSameBehavior(serializedObjects[i], testObjects[i])) {
50                errln("Input object " + className + "(" + i + ") failed behavior test.");
51            }
52        }
53    }
54
55    List<String> generateClassList() throws IOException {
56        return SerializableTestUtility.getSerializationClassList(this);
57    }
58
59}
60