Merge branch 'master' into bael-7169-update-readme

This commit is contained in:
Maiklins
2023-12-10 19:00:44 +01:00
committed by GitHub
484 changed files with 5785 additions and 1041 deletions
@@ -9,4 +9,5 @@ This module contains articles about core features in the Java language
- [Get a Random Element From a Set in Java](https://www.baeldung.com/java-set-draw-sample)
- [Stop Executing Further Code in Java](https://www.baeldung.com/java-stop-running-code)
- [Using the Apache Commons Lang 3 for Comparing Objects in Java](https://www.baeldung.com/java-apache-commons-lang-3-compare-objects)
- [Return First Non-null Value in Java](https://www.baeldung.com/java-first-non-null)
- [Static Final Variables in Java](https://www.baeldung.com/java-static-final-variables)
@@ -0,0 +1,14 @@
package com.baeldung.staticfinal;
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,33 @@
package com.baeldung.staticfinal;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
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"));
}
@Test
void givenMathClass_whenAccessingPiConstant_thenVerifyPiValueIsCorrect() {
assertEquals(3.141592653589793, Math.PI);
}
}