changing public static final field example

This commit is contained in:
m.raheem 2019-08-18 13:54:19 +02:00
parent 8d96692840
commit 12bc0fcfd9
2 changed files with 11 additions and 1 deletions

View File

@ -10,6 +10,7 @@ public class Student {
private BigDecimal grade; //new representation
private String name;
private int age;
public static final String GENDER = "male";
public int getGrade() {
return grade.intValue(); //Backward compatibility
@ -33,6 +34,10 @@ public class Student {
this.age = age;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return this.name;

View File

@ -4,10 +4,10 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import com.baeldung.accessmodifiers.publicmodifier.ListOfThree;
import com.baeldung.accessmodifiers.publicmodifier.Student;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
@ -22,6 +22,11 @@ public class PublicAccessModifierUnitTest {
assertEquals(0, new BigDecimal(0).intValue()); //instance member
}
@Test
public void whenUsingGenderPublicStaticFinalField_getReferenceToStringMale() {
assertEquals("male", Student.GENDER);
}
@Test
public void whenUsingIntegerMaxValueField_maxPossibleIntValueIsReturned() {
assertEquals(2147483647, Integer.MAX_VALUE); //static field