* BAEL-2075: Lombok @Getter for boolean field
This commit is contained in:
codehunter34 2018-09-10 19:02:07 +03:00 committed by Josh Cummings
parent 7a099e385e
commit 3d7a417021
6 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package com.baeldung.lombok.getter;
import lombok.Getter;
/**
* Related Article Sections:
* 4. Using @Getter on a Boolean Field
*
*/
public class GetterBoolean {
@Getter
private Boolean running = true;
}

View File

@ -0,0 +1,16 @@
package com.baeldung.lombok.getter;
import lombok.Getter;
/**
* Related Article Sections:
* 3. Using @Getter on a boolean Field
*
*/
public class GetterBooleanPrimitive {
@Getter
private boolean running;
}

View File

@ -0,0 +1,18 @@
package com.baeldung.lombok.getter;
import lombok.Getter;
/**
* Related Article Sections:
* 3.2. Two boolean Fields With the Same Accessor Name
*
*/
public class GetterBooleanPrimitiveSameAccessor {
@Getter
boolean running = true;
@Getter
boolean isRunning = false;
}

View File

@ -0,0 +1,13 @@
package com.baeldung.lombok.getter;
import lombok.Getter;
/**
* Related Article Sections:
* 3.1. A boolean Field Having the Same Name With Its Accessor
*
*/
public class GetterBooleanSameAccessor {
@Getter
private boolean isRunning = true;
}

View File

@ -0,0 +1,15 @@
package com.baeldung.lombok.getter;
import lombok.Getter;
/**
* Related Article Sections:
* 4. Using @Getter on a Boolean Field
*
*/
public class GetterBooleanType {
@Getter
private Boolean running = true;
}

View File

@ -0,0 +1,34 @@
package com.baeldung.lombok.getter;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class GetterBooleanUnitTest {
@Test
public void whenBasicBooleanField_thenMethodNamePrefixedWithIsFollowedByFieldName() {
GetterBooleanPrimitive lombokExamples = new GetterBooleanPrimitive();
assertFalse(lombokExamples.isRunning());
}
@Test
public void whenBooleanFieldPrefixedWithIs_thenMethodNameIsSameAsFieldName() {
GetterBooleanSameAccessor lombokExamples = new GetterBooleanSameAccessor();
assertTrue(lombokExamples.isRunning());
}
@Test
public void whenTwoBooleanFieldsCauseNamingConflict_thenLombokMapsToFirstDeclaredField() {
GetterBooleanPrimitiveSameAccessor lombokExamples = new GetterBooleanPrimitiveSameAccessor();
assertTrue(lombokExamples.isRunning() == lombokExamples.running);
assertFalse(lombokExamples.isRunning() == lombokExamples.isRunning);
}
@Test
public void whenFieldOfBooleanType_thenLombokPrefixesMethodWithGetInsteadOfIs() {
GetterBooleanType lombokExamples = new GetterBooleanType();
assertTrue(lombokExamples.getRunning());
}
}