Final Static Variables in Java
This commit is contained in:
parent
dea22a6863
commit
692f3b201a
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.finalstatic;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Bike {
|
||||
public static final int TIRE = 2;
|
||||
public static final int PEDAL;
|
||||
public static final HashMap<String, Integer> PART = new HashMap<>();
|
||||
|
||||
static {
|
||||
PEDAL = 5;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.finalstatic;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BikeUnitTest {
|
||||
|
||||
@Test
|
||||
void givenTireConstantSetUponDeclaration_whenGetTire_thenReturnTwo() {
|
||||
assertEquals(2, Bike.TIRE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPedalConstantSetByStaticBlock_whenGetPedal_thenReturnFive() {
|
||||
assertEquals(5, Bike.PEDAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPartConstantObject_whenObjectStateChanged_thenCorrect() {
|
||||
Bike.PART.put("seat", 1);
|
||||
assertEquals(1, Bike.PART.get("seat"));
|
||||
|
||||
Bike.PART.put("seat", 5);
|
||||
assertEquals(5, Bike.PART.get("seat"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue