parent
7a099e385e
commit
3d7a417021
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue