Remove unnecessary spy annotation and make unit tests package private
This commit is contained in:
parent
a8e298e389
commit
392928ccfa
|
@ -19,7 +19,7 @@ public class ReturnFirstNonEmptyOptionalUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfOptionals_thenReturnFirstNonEmpty() {
|
||||
void givenListOfOptionals_thenReturnFirstNonEmpty() {
|
||||
Optional<String> object = optionals.stream()
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
|
|
|
@ -13,15 +13,13 @@ import java.util.stream.Stream;
|
|||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Spy;
|
||||
|
||||
public class ReturnFirstNonNullLazyEvaluateUnitTest {
|
||||
|
||||
@Spy
|
||||
private final LazyEvaluate spy = Mockito.spy(new LazyEvaluate());
|
||||
|
||||
@Test
|
||||
public void givenChainOfMethods_thenLazilyEvaluateMethodsUntilFirstNonNull() {
|
||||
void givenChainOfMethods_thenLazilyEvaluateMethodsUntilFirstNonNull() {
|
||||
String object = spy.methodA();
|
||||
if (object == null) {
|
||||
object = spy.methodB();
|
||||
|
@ -38,7 +36,7 @@ public class ReturnFirstNonNullLazyEvaluateUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenChainOfMethods_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
void givenChainOfMethods_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
String object = ObjectUtils.getFirstNonNull(spy::methodA, spy::methodB, spy::methodC);
|
||||
|
||||
assertEquals("first non null", object);
|
||||
|
@ -48,7 +46,7 @@ public class ReturnFirstNonNullLazyEvaluateUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenChainOfMethods_whenUsingSupplierInterface_thenLazilyEvaluateMethodsUntilFirstNonNull() {
|
||||
void givenChainOfMethods_whenUsingSupplierInterface_thenLazilyEvaluateMethodsUntilFirstNonNull() {
|
||||
Optional<String> object = Stream.<Supplier<String>> of(spy::methodA, spy::methodB, spy::methodC)
|
||||
.map(Supplier::get)
|
||||
.filter(Objects::nonNull)
|
||||
|
@ -61,7 +59,7 @@ public class ReturnFirstNonNullLazyEvaluateUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenNonNullObjectAndFallbackMethod_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
void givenNonNullObjectAndFallbackMethod_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
String nonNullObject = spy.methodB();
|
||||
String object = ObjectUtils.getIfNull(nonNullObject, spy::methodC);
|
||||
|
||||
|
@ -70,7 +68,7 @@ public class ReturnFirstNonNullLazyEvaluateUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenNullObjectAndFallbackMethod_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
void givenNullObjectAndFallbackMethod_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
String nullObject = null;
|
||||
String object = ObjectUtils.getIfNull(nullObject, spy::methodB);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class ReturnFirstNonNullUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfObjects_whenFilterIsLambdaNullCheck_thenReturnFirstNonNull() {
|
||||
void givenListOfObjects_whenFilterIsLambdaNullCheck_thenReturnFirstNonNull() {
|
||||
Optional<String> object = objects.stream()
|
||||
.filter(o -> o != null)
|
||||
.findFirst();
|
||||
|
@ -35,7 +35,7 @@ public class ReturnFirstNonNullUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfObjects_whenFilterIsMethodRefNullCheck_thenReturnFirstNonNull() {
|
||||
void givenListOfObjects_whenFilterIsMethodRefNullCheck_thenReturnFirstNonNull() {
|
||||
Optional<String> object = objects.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.findFirst();
|
||||
|
@ -44,7 +44,7 @@ public class ReturnFirstNonNullUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfObjects_whenIteratingWithForLoop_thenReturnFirstNonNull() {
|
||||
void givenListOfObjects_whenIteratingWithForLoop_thenReturnFirstNonNull() {
|
||||
String object = null;
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
if (objects.get(i) != null) {
|
||||
|
@ -57,21 +57,21 @@ public class ReturnFirstNonNullUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfObjects_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
void givenListOfObjects_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
|
||||
String object = ObjectUtils.firstNonNull(objects.toArray(new String[0]));
|
||||
|
||||
assertEquals("first non null", object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfObjects_whenUsingGoogleGuavaIterables_thenReturnFirstNonNull() {
|
||||
void givenListOfObjects_whenUsingGoogleGuavaIterables_thenReturnFirstNonNull() {
|
||||
String object = Iterables.find(objects, Predicates.notNull());
|
||||
|
||||
assertEquals("first non null", object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoObjects_whenUsingGoogleGuavaMoreObjects_thenReturnFirstNonNull() {
|
||||
void givenTwoObjects_whenUsingGoogleGuavaMoreObjects_thenReturnFirstNonNull() {
|
||||
String nullObject = null;
|
||||
String nonNullObject = "first non null";
|
||||
String object = MoreObjects.firstNonNull(nullObject, nonNullObject);
|
||||
|
|
Loading…
Reference in New Issue