Skip to content

Commit

Permalink
added tests for accessors and chain config parameter
Browse files Browse the repository at this point in the history
Configuration keys #53
  • Loading branch information
Michail Plushnikov committed Mar 28, 2016
1 parent 09487d2 commit 553ac36
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 5 deletions.
Expand Up @@ -22,6 +22,8 @@

public class LombokConfigCompletionContributor extends CompletionContributor {

private static final String LOMBOK_EQUALS_AND_HASH_CODE_CALL_SUPER = "lombok.equalsAndHashCode.callSuper";

public LombokConfigCompletionContributor() {
final Collection<String> booleanOptions = new HashSet<String>(Arrays.asList(
"config.stopBubbling", "lombok.accessors.chain", "lombok.accessors.fluent",
Expand All @@ -41,7 +43,7 @@ public LombokConfigCompletionContributor() {
"lombok.wither.flagUsage"));

final Collection<String> otherOptions = new HashSet<String>(Arrays.asList(
"lombok.accessors.prefix", "lombok.log.fieldName", "lombok.nonNull.exceptionType"));
"lombok.accessors.prefix", "lombok.log.fieldName", "lombok.nonNull.exceptionType", LOMBOK_EQUALS_AND_HASH_CODE_CALL_SUPER));

final Collection<String> allOptions = new HashSet<String>(booleanOptions);
allOptions.addAll(flagUsageOptions);
Expand All @@ -60,6 +62,10 @@ public void addCompletions(@NotNull CompletionParameters parameters, ProcessingC
} else if (flagUsageOptions.contains(configPropertyKey)) {
resultSet.addElement(LookupElementBuilder.create("WARNING"));
resultSet.addElement(LookupElementBuilder.create("ERROR"));
} else if (LOMBOK_EQUALS_AND_HASH_CODE_CALL_SUPER.equals(configPropertyKey)) {
resultSet.addElement(LookupElementBuilder.create("CALL"));
resultSet.addElement(LookupElementBuilder.create("SKIP"));
resultSet.addElement(LookupElementBuilder.create("WARN"));
}
}
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ public enum ConfigKeys {
SINGULAR_USE_GUAVA("lombok.singular.useGuava", "false"),
SINGULAR_AUTO("lombok.singular.auto", "true"),

NONNULL_EXCEPTIONTYPE("lombok.nonNull.exceptionType", "NullPointerException");
NONNULL_EXCEPTIONTYPE("lombok.nonNull.exceptionType", "java.lang.NullPointerException");

private final String configKey;
private final String configDefaultValue;
Expand Down
Expand Up @@ -61,17 +61,17 @@ public static AccessorsInfo build(@Nullable PsiClass psiClass) {
return build(false, false, doNotUseIsPrefix);
}

private static AccessorsInfo buildFromAnnotation(@NotNull PsiAnnotation accessorsAnnotation, @Nullable PsiClass psiClass) {
private static AccessorsInfo buildFromAnnotation(@NotNull PsiAnnotation accessorsAnnotation, @NotNull PsiClass psiClass) {
final boolean isFluent = AbstractProcessor.readAnnotationOrConfigProperty(accessorsAnnotation, psiClass, "fluent", ConfigKeys.ACCESSORS_FLUENT);
final boolean isChained = AbstractProcessor.readAnnotationOrConfigProperty(accessorsAnnotation, psiClass, "chain", ConfigKeys.ACCESSORS_CHAIN);

Boolean chainDeclaredValue = PsiAnnotationUtil.getDeclaredBooleanAnnotationValue(accessorsAnnotation, "chain");
Collection<String> prefixes = PsiAnnotationUtil.getAnnotationValues(accessorsAnnotation, "prefix", String.class);

final boolean dontUseIsPrefix = ConfigDiscovery.getInstance().getBooleanLombokConfigProperty(ConfigKeys.GETTER_NO_IS_PREFIX, psiClass);
final boolean doNotUseIsPrefix = ConfigDiscovery.getInstance().getBooleanLombokConfigProperty(ConfigKeys.GETTER_NO_IS_PREFIX, psiClass);

boolean isChainDeclaredOrImplicit = isChained || (isFluent && null == chainDeclaredValue);
return new AccessorsInfo(isFluent, isChainDeclaredOrImplicit, dontUseIsPrefix, prefixes.toArray(new String[prefixes.size()]));
return new AccessorsInfo(isFluent, isChainDeclaredOrImplicit, doNotUseIsPrefix, prefixes.toArray(new String[prefixes.size()]));
}

public boolean isFluent() {
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 AccessorsTest extends AbstractLombokConfigSystemTestCase {

protected boolean shouldCompareAnnotations() {
return true;
}

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

public void testChain$GetterSetterFieldTest() throws IOException {
doTest();
}

public void testChain$GetterSetterFieldAnnotationOverwriteTest() throws IOException {
doTest();
}

public void testChain$GetterSetterClassTest() throws IOException {
doTest();
}

public void testChain$GetterSetterClassAnnotationOverwriteTest() throws IOException {
doTest();
}
}
@@ -0,0 +1,23 @@
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = false)
public class GetterSetterClassAnnotationOverwriteTest {
private int intProperty;
private double doubleProperty;
private boolean booleanProperty;
private String stringProperty;

public static void main(String[] args) {
final GetterSetterClassAnnotationOverwriteTest test = new GetterSetterClassAnnotationOverwriteTest();
test.setStringProperty("");
test.setIntProperty(1)
test.setBooleanProperty(true)
test.setDoubleProperty(0.0);

System.out.println(test);
}
}
23 changes: 23 additions & 0 deletions testData/configsystem/accessors/chain/GetterSetterClassTest.java
@@ -0,0 +1,23 @@
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
public class GetterSetterFieldTest {
private int intProperty;
private double doubleProperty;
private boolean booleanProperty;
private String stringProperty;

public static void main(String[] args) {
final GetterSetterClassTest test = new GetterSetterClassTest();
test.setStringProperty("")
.setIntProperty(1)
.setBooleanProperty(true)
.setDoubleProperty(0.0);

System.out.println(test);
}
}
@@ -0,0 +1,26 @@
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
public class GetterSetterFieldAnnotationOverwriteTest {
@Accessors(chain=false)
private int intProperty;
@Accessors(chain=false)
private double doubleProperty;
@Accessors(chain=false)
private boolean booleanProperty;
@Accessors(chain=false)
private String stringProperty;

public static void main(String[] args) {
final GetterSetterFieldAnnotationOverwriteTest test = new GetterSetterFieldAnnotationOverwriteTest();
test.setStringProperty("");
test.setIntProperty(1)
test.setBooleanProperty(true)
test.setDoubleProperty(0.0);

System.out.println(test);
}
}
26 changes: 26 additions & 0 deletions testData/configsystem/accessors/chain/GetterSetterFieldTest.java
@@ -0,0 +1,26 @@
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
public class GetterSetterFieldTest {
@Accessors
private int intProperty;
@Accessors
private double doubleProperty;
@Accessors
private boolean booleanProperty;
@Accessors
private String stringProperty;

public static void main(String[] args) {
final GetterSetterFieldTest test = new GetterSetterFieldTest();
test.setStringProperty("")
.setIntProperty(1)
.setBooleanProperty(true)
.setDoubleProperty(0.0);

System.out.println(test);
}
}
@@ -0,0 +1,48 @@
public class GetterSetterClassAnnotationOverwriteTest {
private int intProperty;
private double doubleProperty;
private boolean booleanProperty;
private String stringProperty;

public static void main(String[] args) {
final GetterSetterClassAnnotationOverwriteTest test = new GetterSetterClassAnnotationOverwriteTest();
test.setStringProperty("");
test.setIntProperty(1)
test.setBooleanProperty(true)
test.setDoubleProperty(0.0);

System.out.println(test);
}

public int getIntProperty() {
return this.intProperty;
}

public double getDoubleProperty() {
return this.doubleProperty;
}

public boolean isBooleanProperty() {
return this.booleanProperty;
}

public String getStringProperty() {
return this.stringProperty;
}

public void setIntProperty(int intProperty) {
this.intProperty = intProperty;
}

public void setDoubleProperty(double doubleProperty) {
this.doubleProperty = doubleProperty;
}

public void setBooleanProperty(boolean booleanProperty) {
this.booleanProperty = booleanProperty;
}

public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
}
@@ -0,0 +1,52 @@
public class GetterSetterFieldTest {
private int intProperty;
private double doubleProperty;
private boolean booleanProperty;
private String stringProperty;

public static void main(String[] args) {
final GetterSetterClassTest test = new GetterSetterClassTest();
test.setStringProperty("")
.setIntProperty(1)
.setBooleanProperty(true)
.setDoubleProperty(0.0);

System.out.println(test);
}

public int getIntProperty() {
return this.intProperty;
}

public double getDoubleProperty() {
return this.doubleProperty;
}

public boolean isBooleanProperty() {
return this.booleanProperty;
}

public String getStringProperty() {
return this.stringProperty;
}

public GetterSetterFieldTest setIntProperty(int intProperty) {
this.intProperty = intProperty;
return this;
}

public GetterSetterFieldTest setDoubleProperty(double doubleProperty) {
this.doubleProperty = doubleProperty;
return this;
}

public GetterSetterFieldTest setBooleanProperty(boolean booleanProperty) {
this.booleanProperty = booleanProperty;
return this;
}

public GetterSetterFieldTest setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
return this;
}
}
@@ -0,0 +1,48 @@
public class GetterSetterFieldAnnotationOverwriteTest {
private int intProperty;
private double doubleProperty;
private boolean booleanProperty;
private String stringProperty;

public static void main(String[] args) {
final GetterSetterFieldAnnotationOverwriteTest test = new GetterSetterFieldAnnotationOverwriteTest();
test.setStringProperty("");
test.setIntProperty(1)
test.setBooleanProperty(true)
test.setDoubleProperty(0.0);

System.out.println(test);
}

public int getIntProperty() {
return this.intProperty;
}

public double getDoubleProperty() {
return this.doubleProperty;
}

public boolean isBooleanProperty() {
return this.booleanProperty;
}

public String getStringProperty() {
return this.stringProperty;
}

public void setIntProperty(int intProperty) {
this.intProperty = intProperty;
}

public void setDoubleProperty(double doubleProperty) {
this.doubleProperty = doubleProperty;
}

public void setBooleanProperty(boolean booleanProperty) {
this.booleanProperty = booleanProperty;
}

public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
}

0 comments on commit 553ac36

Please sign in to comment.