Skip to content

Commit

Permalink
- added tests for equalsandhashcode and doNotUseGetters config parameter
Browse files Browse the repository at this point in the history
- fixed equalsandhashcode and doNotUseGetters config parameter for hashcode
Configuration keys #53
  • Loading branch information
Michail Plushnikov committed Mar 27, 2016
1 parent 1c8529e commit b782d76
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 9 deletions.
Expand Up @@ -280,7 +280,7 @@ private String createEqualsBlockString(@NotNull PsiClass psiClass, @NotNull PsiA

private String createHashcodeBlockString(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) {
final boolean callSuper = PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, "callSuper", false);
final boolean doNotUseGetters = PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, "doNotUseGetters", false);
final boolean doNotUseGetters = readAnnotationOrConfigProperty(psiAnnotation, psiClass, "doNotUseGetters", ConfigKeys.EQUALSANDHASHCODE_DO_NOT_USE_GETTERS);

final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
Expand Down
@@ -0,0 +1,34 @@
package de.plushnikov.intellij.plugin.configsystem;

import java.io.IOException;

/**
* Unit tests for IntelliJPlugin for Lombok with activated config system
*/
public class EqualsAndHashCodeTest extends AbstractLombokConfigSystemTestCase {

protected boolean shouldCompareAnnotations() {
return true;
}

@Override
protected String getBasePath() {
return super.getBasePath() + "/configsystem/equalsandhashcode";
}

public void testDoNotUseGetters$SomeTest() throws IOException {
doTest();
}

public void testDoNotUseGetters$AnnotationOverwriteTest() throws IOException {
doTest();
}

public void testCallSuper$WithSuperTest() throws IOException {
doTest();
}

public void testCallSuper$WithoutSuperTest() throws IOException {
doTest();
}
}
75 changes: 67 additions & 8 deletions test-manual/src/main/java/de/plushnikov/test/SomeTest.java
@@ -1,15 +1,74 @@
package de.plushnikov.test;

import lombok.Getter;

@Getter
public class SomeTest {

private int a;
private int intProperty;
private boolean booleanProperty;
private double doubleProperty;
private String stringProperty;

public int getIntProperty() {
return intProperty;
}

public boolean isBooleanProperty() {
return booleanProperty;
}

public double getDoubleProperty() {
return doubleProperty;
}

public static void main(String[] args) {
SomeTest someTest = new SomeTest();
someTest.a = 1;
System.out.println(someTest.a);
public String getStringProperty() {
return stringProperty;
}

public static void main(String[] args) {
final SomeTest test = new SomeTest();
System.out.println(test.hashCode());
}

public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof SomeTest)) {
return false;
}
final SomeTest other = (SomeTest) o;
if (!other.canEqual((Object) this)) {
return false;
}
if (this.intProperty != other.intProperty) {
return false;
}
if (this.booleanProperty != other.booleanProperty) {
return false;
}
if (Double.compare(this.doubleProperty, other.doubleProperty) != 0) {
return false;
}
final Object this$stringProperty = this.stringProperty;
final Object other$stringProperty = other.stringProperty;
if (this$stringProperty == null ? other$stringProperty != null : !this$stringProperty.equals(other$stringProperty)) {
return false;
}
return true;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.intProperty;
result = result * PRIME + (this.booleanProperty ? 79 : 97);
final long $doubleProperty = Double.doubleToLongBits(this.doubleProperty);
result = result * PRIME + (int) ($doubleProperty >>> 32 ^ $doubleProperty);
final Object $stringProperty = this.stringProperty;
result = result * PRIME + ($stringProperty == null ? 0 : $stringProperty.hashCode());
return result;
}

protected boolean canEqual(Object other) {
return other instanceof SomeTest;
}
}
@@ -0,0 +1,31 @@
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(doNotUseGetters = false)
public class AnnotationOverwriteTest {

private int intProperty;
private boolean booleanProperty;
private double doubleProperty;
private String stringProperty;

public int getIntProperty() {
return intProperty;
}

public boolean isBooleanProperty() {
return booleanProperty;
}

public double getDoubleProperty() {
return doubleProperty;
}

public String getStringProperty() {
return stringProperty;
}

public static void main(String[] args) {
final AnnotationOverwriteTest test = new AnnotationOverwriteTest();
System.out.println(test.hashCode());
}
}
@@ -0,0 +1,31 @@
import lombok.EqualsAndHashCode;

@EqualsAndHashCode
public class SomeTest {

private int intProperty;
private boolean booleanProperty;
private double doubleProperty;
private String stringProperty;

public int getIntProperty() {
return intProperty;
}

public boolean isBooleanProperty() {
return booleanProperty;
}

public double getDoubleProperty() {
return doubleProperty;
}

public String getStringProperty() {
return stringProperty;
}

public static void main(String[] args) {
final SomeTest test = new SomeTest();
System.out.println(test.hashCode());
}
}
@@ -0,0 +1,59 @@
public class AnnotationOverwriteTest {

private int intProperty;
private boolean booleanProperty;
private double doubleProperty;
private String stringProperty;

public int getIntProperty() {
return intProperty;
}

public boolean isBooleanProperty() {
return booleanProperty;
}

public double getDoubleProperty() {
return doubleProperty;
}

public String getStringProperty() {
return stringProperty;
}

public static void main(String[] args) {
final AnnotationOverwriteTest test = new AnnotationOverwriteTest();
System.out.println(test.hashCode());
}

public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof AnnotationOverwriteTest)) return false;
final AnnotationOverwriteTest other = (AnnotationOverwriteTest) o;
if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getIntProperty() != other.getIntProperty()) return false;
if (this.isBooleanProperty() != other.isBooleanProperty()) return false;
if (java.lang.Double.compare(this.getDoubleProperty(), other.getDoubleProperty()) != 0) return false;
final java.lang.Object this$stringProperty = this.getStringProperty();
final java.lang.Object other$stringProperty = other.getStringProperty();
if (this$stringProperty == null ? other$stringProperty != null : !this$stringProperty.equals(other$stringProperty))
return false;
return true;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getIntProperty();
result = result * PRIME + (this.isBooleanProperty() ? 79 : 97);
final long $doubleProperty = java.lang.Double.doubleToLongBits(this.getDoubleProperty());
result = result * PRIME + (int) ($doubleProperty >>> 32 ^ $doubleProperty);
final java.lang.Object $stringProperty = this.getStringProperty();
result = result * PRIME + ($stringProperty == null ? 0 : $stringProperty.hashCode());
return result;
}

protected boolean canEqual(java.lang.Object other) {
return other instanceof AnnotationOverwriteTest;
}
}
@@ -0,0 +1,59 @@
public class SomeTest {

private int intProperty;
private boolean booleanProperty;
private double doubleProperty;
private String stringProperty;

public int getIntProperty() {
return intProperty;
}

public boolean isBooleanProperty() {
return booleanProperty;
}

public double getDoubleProperty() {
return doubleProperty;
}

public String getStringProperty() {
return stringProperty;
}

public static void main(String[] args) {
final SomeTest test = new SomeTest();
System.out.println(test.hashCode());
}

public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof SomeTest)) return false;
final SomeTest other = (SomeTest) o;
if (!other.canEqual((java.lang.Object) this)) return false;
if (this.intProperty != other.intProperty) return false;
if (this.booleanProperty != other.booleanProperty) return false;
if (java.lang.Double.compare(this.doubleProperty, other.doubleProperty) != 0) return false;
final java.lang.Object this$stringProperty = this.stringProperty;
final java.lang.Object other$stringProperty = other.stringProperty;
if (this$stringProperty == null ? other$stringProperty != null : !this$stringProperty.equals(other$stringProperty))
return false;
return true;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.intProperty;
result = result * PRIME + (this.booleanProperty ? 79 : 97);
final long $doubleProperty = java.lang.Double.doubleToLongBits(this.doubleProperty);
result = result * PRIME + (int) ($doubleProperty >>> 32 ^ $doubleProperty);
final java.lang.Object $stringProperty = this.stringProperty;
result = result * PRIME + ($stringProperty == null ? 0 : $stringProperty.hashCode());
return result;
}

protected boolean canEqual(java.lang.Object other) {
return other instanceof SomeTest;
}
}
@@ -0,0 +1,3 @@
lombok.equalsAndHashCode.doNotUseGetters = true

config.stopBubbling = true

0 comments on commit b782d76

Please sign in to comment.