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:
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user