mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Merge pull request #2330 from petrkotek/fix-expressions-asType-equals
Expressions: fix equals method
This commit is contained in:
commit
e45c3da02f
@ -1895,6 +1895,18 @@ public final class Expressions {
|
||||
return this.mixin.accept(v, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof BooleanExpression) {
|
||||
BooleanExpression other = (BooleanExpression) o;
|
||||
return (other.mixin.equals(this.mixin));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1933,6 +1945,18 @@ public final class Expressions {
|
||||
return this.mixin.accept(v, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof ComparableExpression) {
|
||||
ComparableExpression other = (ComparableExpression) o;
|
||||
return (other.mixin.equals(this.mixin));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@ -2088,6 +2112,18 @@ public final class Expressions {
|
||||
return this.mixin.accept(v, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof EnumExpression) {
|
||||
EnumExpression other = (EnumExpression) o;
|
||||
return (other.mixin.equals(this.mixin));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@ -2127,6 +2163,18 @@ public final class Expressions {
|
||||
return this.mixin.accept(v, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof NumberExpression) {
|
||||
NumberExpression other = (NumberExpression) o;
|
||||
return (other.mixin.equals(this.mixin));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -2165,6 +2213,17 @@ public final class Expressions {
|
||||
return this.mixin.accept(v, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof StringExpression) {
|
||||
StringExpression other = (StringExpression) o;
|
||||
return (other.mixin.equals(this.mixin));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
package com.querydsl.core.types.dsl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Time;
|
||||
@ -36,7 +37,8 @@ public class ExpressionsTest {
|
||||
private static final BooleanExpression a = new BooleanPath("a"), b = new BooleanPath("b");
|
||||
|
||||
private enum testEnum {
|
||||
TEST;
|
||||
TEST,
|
||||
TEST_2
|
||||
}
|
||||
|
||||
private TimeZone timeZone = null;
|
||||
@ -310,6 +312,12 @@ public class ExpressionsTest {
|
||||
assertEquals("true = true", Expressions.asBoolean(true).isTrue().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asBoolean_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asBoolean(true), Expressions.asBoolean(true));
|
||||
assertNotEquals(Expressions.asBoolean(true), Expressions.asBoolean(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asComparable_returns_a_corresponding_ComparableExpression_for_a_given_Expression() {
|
||||
assertEquals("1 = 1",
|
||||
@ -321,6 +329,12 @@ public class ExpressionsTest {
|
||||
assertEquals("1 = 1", Expressions.asComparable(1L).eq(1L).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asComparable_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asComparable(1L), Expressions.asComparable(1L));
|
||||
assertNotEquals(Expressions.asComparable(1L), Expressions.asComparable(2L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asDate_returns_a_corresponding_DateExpression_for_a_given_Expression() {
|
||||
assertEquals("year(Thu Jan 01 00:00:00 UTC 1970)",
|
||||
@ -332,6 +346,12 @@ public class ExpressionsTest {
|
||||
assertEquals("year(Thu Jan 01 00:00:00 UTC 1970)", Expressions.asDate(new Date(1L)).year().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asDate_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asDate(new Date(1L)).year(), Expressions.asDate(new Date(1L)).year());
|
||||
assertNotEquals(Expressions.asDate(new Date(1L)).year(), Expressions.asDate(new Date(2L)).year());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asDateTime_returns_a_corresponding_DateTimeExpression_for_a_given_Expression() {
|
||||
assertEquals("min(Thu Jan 01 00:00:00 UTC 1970)",
|
||||
@ -343,6 +363,12 @@ public class ExpressionsTest {
|
||||
assertEquals("min(Thu Jan 01 00:00:00 UTC 1970)", Expressions.asDateTime(new Date(1L)).min().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asDateTime_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asDateTime(new Date(1L)).min(), Expressions.asDateTime(new Date(1L)).min());
|
||||
assertNotEquals(Expressions.asDateTime(new Date(1L)).min(), Expressions.asDateTime(new Date(2L)).min());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asTime_returns_a_corresponding_TimeExpression_for_a_given_Expression() {
|
||||
assertEquals("hour(Thu Jan 01 00:00:00 UTC 1970)",
|
||||
@ -354,6 +380,12 @@ public class ExpressionsTest {
|
||||
assertEquals("hour(Thu Jan 01 00:00:00 UTC 1970)", Expressions.asTime(new Date(1L)).hour().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asTime_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asTime(new Date(1L)).hour(), Expressions.asTime(new Date(1L)).hour());
|
||||
assertNotEquals(Expressions.asTime(new Date(1L)).hour(), Expressions.asTime(new Date(2L)).hour());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asEnum_returns_a_corresponding_EnumExpression_for_a_given_Expression() {
|
||||
assertEquals("ordinal(TEST)", Expressions.asEnum(Expressions.constant(testEnum.TEST)).ordinal().toString());
|
||||
@ -364,6 +396,12 @@ public class ExpressionsTest {
|
||||
assertEquals("ordinal(TEST)", Expressions.asEnum(testEnum.TEST).ordinal().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asEnum_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asEnum(testEnum.TEST), Expressions.asEnum(testEnum.TEST));
|
||||
assertNotEquals(Expressions.asEnum(testEnum.TEST), Expressions.asEnum(testEnum.TEST_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asNumber_returns_a_corresponding_NumberExpression_for_a_given_Expression() {
|
||||
assertEquals("1 + 1", Expressions.asNumber(Expressions.constant(1L)).add(Expressions.constant(1L)).toString());
|
||||
@ -374,6 +412,12 @@ public class ExpressionsTest {
|
||||
assertEquals("1 + 1", Expressions.asNumber(1L).add(Expressions.constant(1L)).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asNumber_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asNumber(42L), Expressions.asNumber(42L));
|
||||
assertNotEquals(Expressions.asNumber(42L), Expressions.asNumber(256L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asString_returns_a_corresponding_StringExpression_for_a_given_Expression() {
|
||||
assertEquals("left + right",
|
||||
@ -385,4 +429,10 @@ public class ExpressionsTest {
|
||||
assertEquals("left + right", Expressions.asString("left").append(Expressions.constant("right")).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asString_equals_works_for_returned_values() {
|
||||
assertEquals(Expressions.asString("foo"), Expressions.asString("foo"));
|
||||
assertNotEquals(Expressions.asString("foo"), Expressions.asString("bar"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user