Package org.jmock.core

Examples of org.jmock.core.Constraint


        final long beforeTime = System.currentTimeMillis();

        Mock monitor = mock(ComponentMonitor.class);
        Constructor emptyHashMapCtor = HashMap.class.getConstructor(new Class[0]);
        monitor.expects(once()).method("instantiating").with(eq(emptyHashMapCtor));
        Constraint startIsAfterBegin = new Constraint() {
            public boolean eval(Object o) {
                Long startTime = (Long) o;
                return beforeTime <= startTime.longValue();
            }

            public StringBuffer describeTo(StringBuffer stringBuffer) {
                return stringBuffer.append("The startTime wasn't after the begin of the test");
            }
        };
        Constraint durationIsGreaterThanOrEqualToZero = new Constraint() {
            public boolean eval(Object o) {
                Long duration = (Long) o;
                return 0 <= duration.longValue();
            }
View Full Code Here


        Mock monitor = mock(ComponentMonitor.class);
        Constructor barfingActionListenerCtor = BarfingActionListener.class.getConstructor(new Class[0]);
        monitor.expects(once()).method("instantiating").with(eq(barfingActionListenerCtor));

        Constraint isITE = new Constraint() {
            public boolean eval(Object o) {
                Exception ex = (Exception) o;
                return ex instanceof InvocationTargetException;
            }
View Full Code Here

  }

  private TypeHelper th = new TypeHelper();

  private Constraint checkDefaults(final Map def) {
    return new Constraint() {

      public StringBuffer describeTo(StringBuffer arg0) {
        return arg0.append("default map: " + def);
      }
View Full Code Here

    p.setDateOfBirth(date);
    p.setGender("M");
    p.setLogin("ut061111");
    Object o = mapper.map(p,null);
    System.err.println(o);
    Constraint ctr = addOpCheck01();
    StringBuffer sb = new StringBuffer();
    ctr.describeTo(sb);
    System.err.println(sb);
   
    assertTrue(ctr.eval(o));
  }
View Full Code Here

    public MethodNameMatcher( Constraint constraint ) {
        this.constraint = constraint;
    }

    public MethodNameMatcher( final String methodName ) {
        this(new Constraint()
        {
            public boolean eval( Object o ) {
                return methodName.equals(o);
            }
View Full Code Here

        void doStuff(String name, int number);
    }

    @Test public void
    adaptsHamcrestMatcherToJMockConstraint() {
        Constraint jMockConstraint = new JMock1Adapter(equalTo("expected"));
        assertTrue("Should have matched", jMockConstraint.eval("expected"));
        assertFalse("Should not have matched", jMockConstraint.eval("unexpected"));
    }
View Full Code Here

        assertFalse("Should not have matched", jMockConstraint.eval("unexpected"));
    }

    @Test public void
    delegatesDescriptionToUnderlyingMatcher() {
        Constraint jMockConstraint = new JMock1Adapter(new BaseMatcher<Object>() {
            @Override
            public boolean matches(Object o) {
                return false;
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("is like ");
                description.appendValue("cheese");
            }
        });

        StringBuffer buffer = new StringBuffer();
        buffer = jMockConstraint.describeTo(buffer);
        assertEquals("is like \"cheese\"", buffer.toString());
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
  public void testCreateIssue() throws Exception {
        issueCreator.setIssueParams(new HashMap());
        mockXmlRpcClient.expects(once()).method("execute").with(eq("jira1.createIssue"), new Constraint() {
            public boolean eval(Object object) {
                Object[] arr = (Object[]) object;
                Map issueParams = (Map) arr[1];

                return arr[0] instanceof String && issueParams.containsKey("summary") && issueParams.containsKey("description");
View Full Code Here

TOP

Related Classes of org.jmock.core.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.