Skip to content

Commit 49d005b

Browse files
authored
Feature/bael 5609 static method (#12370)
* BAEL-5609: init * BAEL-5609: update examples * BAEL-5609: refactor * BAEL-5609: delete car example
1 parent 90274ec commit 49d005b

7 files changed

Lines changed: 123 additions & 0 deletions

File tree

core-java-modules/core-java-function/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
<version>0.0.1-SNAPSHOT</version>
1515
</parent>
1616

17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.commons</groupId>
20+
<artifactId>commons-lang3</artifactId>
21+
<version>${commons-lang3.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.assertj</groupId>
25+
<artifactId>assertj-core</artifactId>
26+
<version>${assertj.version}</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.mockito</groupId>
31+
<artifactId>mockito-inline</artifactId>
32+
<version>${mockito-inline.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
1737
<build>
1838
<finalName>core-java-function</finalName>
1939
<resources>
@@ -24,4 +44,10 @@
2444
</resources>
2545
</build>
2646

47+
<properties>
48+
<mockito-inline.version>3.8.0</mockito-inline.version>
49+
<assertj.version>3.22.0</assertj.version>
50+
<commons-lang3.version>3.12.0</commons-lang3.version>
51+
</properties>
52+
2753
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.staticmethods;
2+
3+
public final class CustomStringUtils {
4+
5+
private CustomStringUtils() {}
6+
7+
public static boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; }
8+
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.staticmethods;
2+
3+
public class StaticCounter {
4+
5+
private static int counter = 0;
6+
7+
public static int incrementCounter() {
8+
return ++counter;
9+
}
10+
11+
public static int getCounterValue() {
12+
return counter;
13+
}
14+
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.staticmethods;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.Arrays;
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
class CollectionUtilsUnitTest {
12+
13+
@Test
14+
void givenListOfNumbers_whenReverseStaticMethodIsCalled_thenNumbersInReversedOrderAreReturned() {
15+
List<String> list = Arrays.asList("1", "2", "3");
16+
Collections.reverse(list);
17+
assertThat(list).containsExactly("3", "2", "1");
18+
}
19+
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.staticmethods;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
class CustomStringUtilsUnitTest {
8+
9+
@Test
10+
void givenNonEmptyString_whenIsEmptyMethodIsCalled_thenFalseIsReturned() {
11+
boolean empty = CustomStringUtils.isEmpty("baeldung");
12+
assertThat(empty).isFalse();
13+
}
14+
15+
@Test
16+
void givenEmptyString_whenIsEmptyMethodIsCalled_thenTrueIsReturned() {
17+
boolean empty = CustomStringUtils.isEmpty("");
18+
assertThat(empty).isTrue();
19+
}
20+
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.staticmethods;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
class StaticCounterUnitTest {
8+
9+
@Test
10+
void givenStaticCounter_whenIncrementCounterIsCalled_thenValueIsIncresedByOne() {
11+
int oldValue = StaticCounter.getCounterValue();
12+
int newValue = StaticCounter.incrementCounter();
13+
assertThat(newValue).isEqualTo(oldValue + 1);
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.staticmethods;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
class StringUtilsUnitTest {
9+
10+
@Test
11+
void givenSimpleString_whenCapitalizeStaticMethodIsCalled_thenCapitalizedStringIsReturned() {
12+
String str = StringUtils.capitalize("baeldung");
13+
assertThat(str).isEqualTo("Baeldung");
14+
}
15+
16+
}

0 commit comments

Comments
 (0)