title: Is there a simple way to match a field using Hamcrest?
body: <p>I want to test whether a specific field of an object matches a value I specify. In this case, it's the bucket name inside an S3Bucket object. As far as I can tell, I need to write a custom matcher for this:</p>
  
  <pre><code>mockery.checking(new Expectations() {{
    one(query.s3).getObject(with(
        new BaseMatcher&lt;S3Bucket&gt;() {
          @Override
          public boolean matches(Object item) {
            if (item instanceof S3Bucket) {
              return ((S3Bucket)item).getName().equals("bucket");
            } else {
              return false;
            }
          }
          @Override
          public void describeTo(Description description) {
            description.appendText("Bucket name isn't \"bucket\"");
          }
        }), with(equal("key")));
      ...
      }});
  </code></pre>
  
  <p>It would be nice if there were a simpler way to do this, something like:</p>
  
  <pre><code>mockery.checking(new Expectations() {{
    one(query.s3).getObject(
      with(equal(methodOf(S3Bucket.class).getName(), "bucket")),
      with(equal("key")));
      ...
  }});
  </code></pre>
  
  <p>Can anyone point me to something like that? I guess I've solved my problem already in this case, but this isn't the first time I've wished for a simpler way.</p>