changing public static final field example
This commit is contained in:
parent
8d96692840
commit
12bc0fcfd9
|
@ -10,6 +10,7 @@ public class Student {
|
||||||
private BigDecimal grade; //new representation
|
private BigDecimal grade; //new representation
|
||||||
private String name;
|
private String name;
|
||||||
private int age;
|
private int age;
|
||||||
|
public static final String GENDER = "male";
|
||||||
|
|
||||||
public int getGrade() {
|
public int getGrade() {
|
||||||
return grade.intValue(); //Backward compatibility
|
return grade.intValue(); //Backward compatibility
|
||||||
|
@ -33,6 +34,10 @@ public class Student {
|
||||||
this.age = age;
|
this.age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
return this.name;
|
||||||
|
|
|
@ -4,10 +4,10 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
import com.baeldung.accessmodifiers.publicmodifier.ListOfThree;
|
import com.baeldung.accessmodifiers.publicmodifier.ListOfThree;
|
||||||
|
import com.baeldung.accessmodifiers.publicmodifier.Student;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
@ -22,6 +22,11 @@ public class PublicAccessModifierUnitTest {
|
||||||
assertEquals(0, new BigDecimal(0).intValue()); //instance member
|
assertEquals(0, new BigDecimal(0).intValue()); //instance member
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingGenderPublicStaticFinalField_getReferenceToStringMale() {
|
||||||
|
assertEquals("male", Student.GENDER);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingIntegerMaxValueField_maxPossibleIntValueIsReturned() {
|
public void whenUsingIntegerMaxValueField_maxPossibleIntValueIsReturned() {
|
||||||
assertEquals(2147483647, Integer.MAX_VALUE); //static field
|
assertEquals(2147483647, Integer.MAX_VALUE); //static field
|
||||||
|
|
Loading…
Reference in New Issue