com.nec.harvest.junit4.BaseTest.java Source code

Java tutorial

Introduction

Here is the source code for com.nec.harvest.junit4.BaseTest.java

Source

/*
 * Copyright(C) 2014
 * NEC Corporation All rights reserved.
 * 
 * No permission to use, copy, modify and distribute this software
 * and its documentation for any purpose is granted.
 * This software is provided under applicable license agreement only.
 */
package com.nec.harvest.junit4;

import java.util.LinkedList;
import java.util.List;

import org.junit.Assert;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author sondn
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextHierarchy({ @ContextConfiguration(locations = { "classpath:spring/applicationContext.xml" }) })
@Configurable
public abstract class BaseTest {

    protected void assertListEqual(List<?> actual, Object... expected) {
        Assert.assertEquals("The list did not have the expected length", expected.length, actual.size());

        List<Object> remaining = new LinkedList<Object>();
        remaining.addAll(actual);

        for (Object o : expected) {
            if (!remaining.remove(o))
                Assert.fail("The list did not match the expected results.");
        }
    }

    protected void assertArrayEqual(Object[] actual, Object... expected) {
        Assert.assertEquals("The array did not have the expected length", expected.length, actual.length);

        List<Object> remaining = new LinkedList<Object>();
        for (Object o : actual) {
            remaining.add(o);
        }

        for (Object o : expected) {
            if (!remaining.remove(o))
                Assert.fail("The array did not match the expected results.");
        }
    }
}