Feature/bael 5609 static method (#12370)

* BAEL-5609: init

* BAEL-5609: update examples

* BAEL-5609: refactor

* BAEL-5609: delete car example
This commit is contained in:
Daniel Strmecki
2022-07-04 20:11:58 +02:00
committed by GitHub
parent 56afb8bda9
commit 8824b85d1c
7 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package com.baeldung.staticmethods;
public final class CustomStringUtils {
private CustomStringUtils() {}
public static boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; }
}

View File

@@ -0,0 +1,15 @@
package com.baeldung.staticmethods;
public class StaticCounter {
private static int counter = 0;
public static int incrementCounter() {
return ++counter;
}
public static int getCounterValue() {
return counter;
}
}

View File

@@ -0,0 +1,20 @@
package com.baeldung.staticmethods;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class CollectionUtilsUnitTest {
@Test
void givenListOfNumbers_whenReverseStaticMethodIsCalled_thenNumbersInReversedOrderAreReturned() {
List<String> list = Arrays.asList("1", "2", "3");
Collections.reverse(list);
assertThat(list).containsExactly("3", "2", "1");
}
}

View File

@@ -0,0 +1,21 @@
package com.baeldung.staticmethods;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class CustomStringUtilsUnitTest {
@Test
void givenNonEmptyString_whenIsEmptyMethodIsCalled_thenFalseIsReturned() {
boolean empty = CustomStringUtils.isEmpty("baeldung");
assertThat(empty).isFalse();
}
@Test
void givenEmptyString_whenIsEmptyMethodIsCalled_thenTrueIsReturned() {
boolean empty = CustomStringUtils.isEmpty("");
assertThat(empty).isTrue();
}
}

View File

@@ -0,0 +1,16 @@
package com.baeldung.staticmethods;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class StaticCounterUnitTest {
@Test
void givenStaticCounter_whenIncrementCounterIsCalled_thenValueIsIncresedByOne() {
int oldValue = StaticCounter.getCounterValue();
int newValue = StaticCounter.incrementCounter();
assertThat(newValue).isEqualTo(oldValue + 1);
}
}

View File

@@ -0,0 +1,16 @@
package com.baeldung.staticmethods;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class StringUtilsUnitTest {
@Test
void givenSimpleString_whenCapitalizeStaticMethodIsCalled_thenCapitalizedStringIsReturned() {
String str = StringUtils.capitalize("baeldung");
assertThat(str).isEqualTo("Baeldung");
}
}