Added missing equals/hashCode methods to some filter classes (LDAP-198).
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.ldap.filter;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -70,4 +72,26 @@ public class HardcodedFilter extends AbstractFilter {
|
||||
buff.append(filter);
|
||||
return buff;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (o instanceof HardcodedFilter && o.getClass() == this.getClass()) {
|
||||
HardcodedFilter f = (HardcodedFilter) o;
|
||||
EqualsBuilder builder = new EqualsBuilder().append(this.filter, f.filter);
|
||||
return builder.isEquals();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
HashCodeBuilder builder = new HashCodeBuilder().append(filter);
|
||||
return builder.toHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.ldap.filter;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.springframework.ldap.filter.AbstractFilter;
|
||||
|
||||
/**
|
||||
@@ -36,7 +38,7 @@ import org.springframework.ldap.filter.AbstractFilter;
|
||||
* @author Jordan Hein
|
||||
*/
|
||||
public class NotPresentFilter extends AbstractFilter {
|
||||
|
||||
|
||||
private String attribute;
|
||||
|
||||
/**
|
||||
@@ -56,4 +58,26 @@ public class NotPresentFilter extends AbstractFilter {
|
||||
buff.append("=*))");
|
||||
return buff;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (o instanceof NotPresentFilter && o.getClass() == this.getClass()) {
|
||||
NotPresentFilter f = (NotPresentFilter) o;
|
||||
EqualsBuilder builder = new EqualsBuilder().append(this.attribute, f.attribute);
|
||||
return builder.isEquals();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
HashCodeBuilder builder = new HashCodeBuilder().append(attribute);
|
||||
return builder.toHashCode();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.ldap.filter;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
/**
|
||||
* Filter that allows the user to check for the existence of a attribute. For an
|
||||
* attribute to be {@code 'present'} it must contain a value. Attributes that do
|
||||
@@ -54,4 +57,26 @@ public class PresentFilter extends AbstractFilter {
|
||||
buff.append("=*)");
|
||||
return buff;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (o instanceof PresentFilter && o.getClass() == this.getClass()) {
|
||||
PresentFilter f = (PresentFilter) o;
|
||||
EqualsBuilder builder = new EqualsBuilder().append(this.attribute, f.attribute);
|
||||
return builder.isEquals();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
HashCodeBuilder builder = new HashCodeBuilder().append(attribute);
|
||||
return builder.toHashCode();
|
||||
}
|
||||
}
|
||||
@@ -64,14 +64,12 @@ public class AndFilterTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
AndFilter originalObject = new AndFilter().and(new EqualsFilter("a",
|
||||
"b"));
|
||||
AndFilter identicalObject = new AndFilter().and(new EqualsFilter("a",
|
||||
"b"));
|
||||
AndFilter differentObject = new AndFilter().and(new EqualsFilter("b",
|
||||
"b"));
|
||||
EqualsFilter filter = new EqualsFilter("a", "b");
|
||||
AndFilter originalObject = new AndFilter().and(filter);
|
||||
AndFilter identicalObject = new AndFilter().and(filter);
|
||||
AndFilter differentObject = new AndFilter().and(new EqualsFilter("b", "b"));
|
||||
AndFilter subclassObject = new AndFilter() {
|
||||
}.and(new EqualsFilter("a", "b"));
|
||||
}.and(filter);
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.ldap.filter;
|
||||
|
||||
import org.springframework.ldap.filter.GreaterThanOrEqualsFilter;
|
||||
|
||||
import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -58,4 +60,16 @@ public class GreaterThanOrEqualsFilterTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
String attribute = "a";
|
||||
String value = "b";
|
||||
GreaterThanOrEqualsFilter originalObject = new GreaterThanOrEqualsFilter(attribute, value);
|
||||
GreaterThanOrEqualsFilter identicalObject = new GreaterThanOrEqualsFilter(attribute, value);
|
||||
GreaterThanOrEqualsFilter differentObject = new GreaterThanOrEqualsFilter(attribute, "c");
|
||||
GreaterThanOrEqualsFilter subclassObject = new GreaterThanOrEqualsFilter(attribute, value) {
|
||||
};
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2005-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.ldap.filter.AndFilter;
|
||||
import org.springframework.ldap.filter.NotFilter;
|
||||
|
||||
import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
|
||||
/**
|
||||
* Unit tests for the HardcodedFilter class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class HardcodedFilterTest extends TestCase {
|
||||
|
||||
public void testHardcodedFilter() {
|
||||
HardcodedFilter filter = new HardcodedFilter("(foo=a*b)");
|
||||
assertEquals("(foo=a*b)", filter.encode());
|
||||
|
||||
NotFilter notFilter = new NotFilter(new HardcodedFilter("(foo=a*b)"));
|
||||
assertEquals("(!(foo=a*b))", notFilter.encode());
|
||||
|
||||
AndFilter andFilter = new AndFilter();
|
||||
andFilter.and(new HardcodedFilter("(foo=a*b)"));
|
||||
andFilter.and(new HardcodedFilter("(bar=a*b)"));
|
||||
assertEquals("(&(foo=a*b)(bar=a*b))", andFilter.encode());
|
||||
|
||||
andFilter = new AndFilter();
|
||||
andFilter.and(new HardcodedFilter("(foo=a*b)"));
|
||||
andFilter.and(new NotFilter(new HardcodedFilter("(bar=a*b)")));
|
||||
assertEquals("(&(foo=a*b)(!(bar=a*b)))", andFilter.encode());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
String attribute = "(foo=a*b)";
|
||||
HardcodedFilter originalObject = new HardcodedFilter(attribute);
|
||||
HardcodedFilter identicalObject = new HardcodedFilter(attribute);
|
||||
HardcodedFilter differentObject = new HardcodedFilter("(bar=a*b)");
|
||||
HardcodedFilter subclassObject = new HardcodedFilter(attribute) {
|
||||
};
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ package org.springframework.ldap.filter;
|
||||
|
||||
import org.springframework.ldap.filter.LessThanOrEqualsFilter;
|
||||
|
||||
import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -57,4 +59,16 @@ public class LessThanOrEqualsFilterTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
String attribute = "a";
|
||||
String value = "b";
|
||||
LessThanOrEqualsFilter originalObject = new LessThanOrEqualsFilter(attribute, value);
|
||||
LessThanOrEqualsFilter identicalObject = new LessThanOrEqualsFilter(attribute, value);
|
||||
LessThanOrEqualsFilter differentObject = new LessThanOrEqualsFilter(attribute, "c");
|
||||
LessThanOrEqualsFilter subclassObject = new LessThanOrEqualsFilter(attribute, value) {
|
||||
};
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.ldap.filter;
|
||||
|
||||
import org.springframework.ldap.filter.LikeFilter;
|
||||
|
||||
import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -33,12 +35,12 @@ public class LikeFilterTest extends TestCase {
|
||||
super(name);
|
||||
}
|
||||
|
||||
final public void testEncodeValue_blank() {
|
||||
public void testEncodeValue_blank() {
|
||||
assertEquals("", new LikeFilter("", null).getEncodedValue());
|
||||
assertEquals(" ", new LikeFilter("", " ").getEncodedValue());
|
||||
}
|
||||
|
||||
final public void testEncodeValue_normal() {
|
||||
public void testEncodeValue_normal() {
|
||||
assertEquals("foo", new LikeFilter("", "foo").getEncodedValue());
|
||||
assertEquals("foo*bar", new LikeFilter("", "foo*bar").getEncodedValue());
|
||||
assertEquals("*foo*bar*", new LikeFilter("", "*foo*bar*")
|
||||
@@ -47,10 +49,22 @@ public class LikeFilterTest extends TestCase {
|
||||
.getEncodedValue());
|
||||
}
|
||||
|
||||
final public void testEncodeValue_escape() {
|
||||
public void testEncodeValue_escape() {
|
||||
assertEquals("*\\28*\\29*", new LikeFilter("", "*(*)*")
|
||||
.getEncodedValue());
|
||||
assertEquals("*\\5c2a*", new LikeFilter("", "*\\2a*").getEncodedValue());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
String attribute = "a";
|
||||
String value = "b";
|
||||
LikeFilter originalObject = new LikeFilter(attribute, value);
|
||||
LikeFilter identicalObject = new LikeFilter(attribute, value);
|
||||
LikeFilter differentObject = new LikeFilter(attribute, "c");
|
||||
LikeFilter subclassObject = new LikeFilter(attribute, value) {
|
||||
};
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the NotFilter class.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class NotFilterTest extends TestCase {
|
||||
|
||||
@@ -20,11 +20,18 @@ import junit.framework.TestCase;
|
||||
import org.springframework.ldap.filter.AndFilter;
|
||||
import org.springframework.ldap.filter.NotFilter;
|
||||
|
||||
import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
|
||||
/**
|
||||
* Unit tests for the NotPresentFilter class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class NotPresentFilterTest extends TestCase {
|
||||
|
||||
public void testNotPresentFilter() {
|
||||
NotPresentFilter presentFilter = new NotPresentFilter("foo");
|
||||
assertEquals("(!(foo=*))", presentFilter.encode());
|
||||
NotPresentFilter filter = new NotPresentFilter("foo");
|
||||
assertEquals("(!(foo=*))", filter.encode());
|
||||
|
||||
NotFilter notFilter = new NotFilter(new NotPresentFilter("foo"));
|
||||
assertEquals("(!(!(foo=*)))", notFilter.encode());
|
||||
@@ -39,4 +46,16 @@ public class NotPresentFilterTest extends TestCase {
|
||||
andFilter.and(new NotFilter(new NotPresentFilter("bar")));
|
||||
assertEquals("(&(!(foo=*))(!(!(bar=*))))", andFilter.encode());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
String attribute = "foo";
|
||||
NotPresentFilter originalObject = new NotPresentFilter(attribute);
|
||||
NotPresentFilter identicalObject = new NotPresentFilter(attribute);
|
||||
NotPresentFilter differentObject = new NotPresentFilter("bar");
|
||||
NotPresentFilter subclassObject = new NotPresentFilter(attribute) {
|
||||
};
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import org.springframework.ldap.filter.OrFilter;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the OrFilter class.
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public class OrFilterTest extends TestCase {
|
||||
|
||||
@@ -20,11 +20,18 @@ import junit.framework.TestCase;
|
||||
import org.springframework.ldap.filter.AndFilter;
|
||||
import org.springframework.ldap.filter.NotFilter;
|
||||
|
||||
import com.gargoylesoftware.base.testing.EqualsTester;
|
||||
|
||||
/**
|
||||
* Unit tests for the PresentFilter class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PresentFilterTest extends TestCase {
|
||||
|
||||
public void testPresentFilter() {
|
||||
PresentFilter presentFilter = new PresentFilter("foo");
|
||||
assertEquals("(foo=*)", presentFilter.encode());
|
||||
PresentFilter filter = new PresentFilter("foo");
|
||||
assertEquals("(foo=*)", filter.encode());
|
||||
|
||||
NotFilter notFilter = new NotFilter(new PresentFilter("foo"));
|
||||
assertEquals("(!(foo=*))", notFilter.encode());
|
||||
@@ -39,4 +46,16 @@ public class PresentFilterTest extends TestCase {
|
||||
andFilter.and(new NotFilter(new PresentFilter("bar")));
|
||||
assertEquals("(&(foo=*)(!(bar=*)))", andFilter.encode());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
String attribute = "foo";
|
||||
PresentFilter originalObject = new PresentFilter(attribute);
|
||||
PresentFilter identicalObject = new PresentFilter(attribute);
|
||||
PresentFilter differentObject = new PresentFilter("bar");
|
||||
PresentFilter subclassObject = new PresentFilter(attribute) {
|
||||
};
|
||||
|
||||
new EqualsTester(originalObject, identicalObject, differentObject,
|
||||
subclassObject);
|
||||
}
|
||||
}
|
||||
@@ -21,20 +21,17 @@ import org.springframework.ldap.filter.WhitespaceWildcardsFilter;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the WhitespaceWildcardsFilter class.
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public class WhitespaceWildcardsFilterTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Constructor for WhitespaceWildcardsFilterTest.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public WhitespaceWildcardsFilterTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
final public void testEncodeValue_blank() {
|
||||
public void testEncodeValue_blank() {
|
||||
|
||||
// blank
|
||||
assertEquals("*", new WhitespaceWildcardsFilter("", null)
|
||||
@@ -48,7 +45,7 @@ public class WhitespaceWildcardsFilterTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
final public void testEncodeValue_normal() {
|
||||
public void testEncodeValue_normal() {
|
||||
|
||||
assertEquals("*foo*", new WhitespaceWildcardsFilter("", "foo")
|
||||
.getEncodedValue());
|
||||
@@ -61,7 +58,7 @@ public class WhitespaceWildcardsFilterTest extends TestCase {
|
||||
" \t foo \n bar \r ").getEncodedValue());
|
||||
}
|
||||
|
||||
final public void testEncodeValue_escape() {
|
||||
public void testEncodeValue_escape() {
|
||||
|
||||
assertEquals("*\\28\\2a\\29*", new WhitespaceWildcardsFilter("", "(*)")
|
||||
.getEncodedValue());
|
||||
@@ -71,5 +68,4 @@ public class WhitespaceWildcardsFilterTest extends TestCase {
|
||||
.getEncodedValue());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user