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:
parent
90274ec48f
commit
49d005b63e
|
@ -14,6 +14,26 @@
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${commons-lang3.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-inline</artifactId>
|
||||||
|
<version>${mockito-inline.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>core-java-function</finalName>
|
<finalName>core-java-function</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -24,4 +44,10 @@
|
||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<mockito-inline.version>3.8.0</mockito-inline.version>
|
||||||
|
<assertj.version>3.22.0</assertj.version>
|
||||||
|
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue