Newer
Older
libj / modules / j / base / test / src / ut_illegal_argument_exception.cpp
#include <iostream>
#include <j/cppunit/cppunit.hpp>
#include <j/cppunit/assert.hpp>
#include <j/lang/illegal_argument_exception.hpp>
#include <j/lang/errno.hpp>

using namespace j;
using namespace j::lang;
using namespace j::cppunit;

class IllegalArgumentExceptionTest : public TestCase
{
public:
    IllegalArgumentExceptionTest() {}
    ~IllegalArgumentExceptionTest() {}
    void setUp() {}
    void tearDown() {}

    void testIllegalArgumentException()
    {
        IllegalArgumentException e;
        String exp = j::lang::Errno::message(j::lang::Errno::get());
        String act = e.getMessage();
        assertEquals(exp, act);
    }

    void testIllegalArgumentExceptionMsg()
    {
        String msg = "ERROR MESSAGE";
        IllegalArgumentException e(msg);
        assertEquals(msg, e.getMessage());
    }

    void testIllegalArgumentExceptionCopy()
    {
        String msg = "ERROR MESSAGE 2";

        IllegalArgumentException e(msg);
        IllegalArgumentException ee = e;
        assertEquals(msg, e.getMessage());
        assertTrue(e != ee);
        assertFalse(e == ee);
    }

    void testIllegalArgumentExceptionMove()
    {
        String msg = "ERROR MESSAGE 3";

        IllegalArgumentException e(msg);
        IllegalArgumentException ee = std::move(e);
        assertEquals(msg, ee.getMessage());
    }

    void testIllegalArgumentExceptionToString()
    {
        String msg = "ERROR MESSAGE 3";
        IllegalArgumentException e(msg);
        assertEquals(msg, e.toString());
    }

    void suite()
    {
        RUN_TEST("new IllegalArgumentException()", testIllegalArgumentException);
        RUN_TEST("new IllegalArgumentException(msg)", testIllegalArgumentExceptionMsg);
        RUN_TEST("copy", testIllegalArgumentExceptionCopy);
        RUN_TEST("move", testIllegalArgumentExceptionMove);
        RUN_TEST("toString()", testIllegalArgumentExceptionToString);
    }
};