Package org.jmock

Examples of org.jmock.Constraint


    public void testIsEventFrom() {
        Object o = new Object();
        EventObject ev = new EventObject(o);
        EventObject ev2 = new EventObject(new Object());

        Constraint p = new IsEventFrom(o);

        assertTrue(p.eval(ev));
        assertTrue("p should eval to false for an event not from o",
                !p.eval(ev2));
        assertTrue("p should eval to false for objects that are not events",
                !p.eval(o));
    }
View Full Code Here


        DerivedEvent good_ev = new DerivedEvent(o);
        DerivedEvent wrong_source = new DerivedEvent(new Object());
        EventObject wrong_type = new EventObject(o);
        EventObject wrong_source_and_type = new EventObject(new Object());

        Constraint p = new IsEventFrom(DerivedEvent.class, o);

        assertTrue(p.eval(good_ev));
        assertTrue("p should eval to false for an event not from o",
                !p.eval(wrong_source));
        assertTrue("p should eval to false for an event of the wrong type",
                !p.eval(wrong_type));
        assertTrue("p should eval to false for an event of the wrong type " +
                "and from the wrong source",
                !p.eval(wrong_source_and_type));
    }
View Full Code Here

                "and from the wrong source",
                !p.eval(wrong_source_and_type));
    }

    public void testIsCloseTo() {
        Constraint p = new IsCloseTo(1.0, 0.5);

        assertTrue(p.eval(new Double(1.0)));
        assertTrue(p.eval(new Double(0.5)));
        assertTrue(p.eval(new Double(1.5)));

        assertTrue(p.eval(new Float(1.0)));
        assertTrue(p.eval(new Integer(1)));

        assertTrue("number too large", !p.eval(new Double(2.0)));
        assertTrue("number too small", !p.eval(new Double(0.0)));

        try {
            p.eval("wrong type");
            fail("ClassCastException expected for wrong type of argument");
        } catch (ClassCastException ex) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.jmock.Constraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.