renaming bigDecimalGrade method + removing the GENDER constant

This commit is contained in:
m.raheem 2019-08-18 16:40:13 +02:00
parent 12bc0fcfd9
commit c1d88b7364
3 changed files with 12 additions and 11 deletions

View File

@ -0,0 +1,7 @@
package com.baeldung.accessmodifiers.publicmodifier;
public class SpecialCharacters {
public static final String SLASH = "/";
}

View File

@ -10,13 +10,12 @@ 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
}
public BigDecimal bigDecimalGrade() {
public BigDecimal getBigDecimalGrade() {
return grade;
}
@ -28,9 +27,10 @@ public class Student {
}
public void setAge(int age) {
if (age < 0 || age > 150)
if (age < 0 || age > 150) {
throw new IllegalArgumentException();
}
this.age = age;
}

View File

@ -4,7 +4,6 @@ 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;
@ -22,16 +21,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
}
@Test
public void whenUsingStringToLowerCase_stringTurnsToLowerCase() {
assertEquals("alex", "ALEX".toLowerCase());