Skip to content

Commit

Permalink
added refEq matcher based on reflectionEquals from apache commons lang
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : svn%3Aaa2aecf3-ea3e-0410-9d70-716747e7c967/trunk%40330
  • Loading branch information
mockitoguy committed Jan 27, 2008
1 parent 3641d50 commit 824fbd7
Show file tree
Hide file tree
Showing 8 changed files with 1,980 additions and 5 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Mockito license - MIT.

Libraries used:

EasyMock - MIT license.
Cglib - Apache License 2.0.
Objenesis - MIT license.
Apache Commons Lang - Apache License 2.0.
11 changes: 6 additions & 5 deletions replace_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
File.open(path, 'r+') do |f|
out = ''
f.each { |line| out << line }

current_hdr = Regexp.new('.*\*/.*package org\.', Regexp::MULTILINE)

if (out =~ current_hdr)
out.gsub!(current_hdr, header + "package org.")
else

if (out !~ current_hdr)
out = header + out
else
first_hdr = Regexp.new('.*?\*/.*?[\n\r]+?', Regexp::MULTILINE)
out.sub!(first_hdr, header)
end

f.pos = 0
Expand Down
19 changes: 19 additions & 0 deletions src/org/mockito/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.mockito.internal.matchers.Null;
import org.mockito.internal.matchers.Same;
import org.mockito.internal.matchers.StartsWith;
import org.mockito.internal.matchers.apachecommons.ReflectionEquals;
import org.mockito.internal.progress.LastArguments;
import org.mockito.internal.progress.ReturnValues;

Expand Down Expand Up @@ -317,6 +318,24 @@ public static <T> T eq(T value) {
return reportMatcher(new Equals(value)).<T>returnNull();
}

/**
* Object argument that is reflection-equal to the given value.
* <p>
* This matcher can be used when equals() is not implemented on compared objects.
* Matcher uses java reflection API to compare fields of wanted and actual object.
* <p>
* Works similarly to EqualsBuilder.reflectionEquals(this, other) from apache commons library.
* <p>
* See examples in javadoc for {@link Matchers}
*
* @param value
* the given value.
* @return <code>null</code>.
*/
public static <T> T refEq(T value) {
return reportMatcher(new ReflectionEquals(value)).<T>returnNull();
}

/**
* Object argument that is the same as the given value.
* <p>
Expand Down
Loading

0 comments on commit 824fbd7

Please sign in to comment.