Build optimization 1.08.2017 (#2351)
* Refactor Spring-activiti module * Refactor vavr module
This commit is contained in:
committed by
GitHub
parent
0c60af8437
commit
ed92182fbf
@@ -1,18 +1,24 @@
|
||||
package com.baeldung.vavr;
|
||||
|
||||
import io.vavr.MatchError;
|
||||
import io.vavr.control.Option;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.vavr.API.$;
|
||||
import static io.vavr.API.Case;
|
||||
import static io.vavr.API.Match;
|
||||
import static io.vavr.API.run;
|
||||
import static io.vavr.Predicates.*;
|
||||
import static io.vavr.Predicates.allOf;
|
||||
import static io.vavr.Predicates.anyOf;
|
||||
import static io.vavr.Predicates.instanceOf;
|
||||
import static io.vavr.Predicates.is;
|
||||
import static io.vavr.Predicates.isIn;
|
||||
import static io.vavr.Predicates.isNotNull;
|
||||
import static io.vavr.Predicates.isNull;
|
||||
import static io.vavr.Predicates.noneOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.vavr.MatchError;
|
||||
import io.vavr.control.Option;
|
||||
|
||||
public class PatternMatchingUnitTest {
|
||||
@Test
|
||||
public void whenMatchesDefault_thenCorrect() {
|
||||
|
||||
@@ -9,7 +9,9 @@ import org.junit.Test;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static io.vavr.API.*;
|
||||
import static io.vavr.API.$;
|
||||
import static io.vavr.API.Case;
|
||||
import static io.vavr.API.Match;
|
||||
|
||||
public class PropertyBasedLongRunningUnitTest {
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ import io.vavr.Function1;
|
||||
import io.vavr.Function2;
|
||||
import io.vavr.Function5;
|
||||
import io.vavr.Lazy;
|
||||
import io.vavr.*;
|
||||
import io.vavr.Tuple;
|
||||
import io.vavr.Tuple2;
|
||||
import io.vavr.Tuple3;
|
||||
import io.vavr.collection.List;
|
||||
import io.vavr.collection.Seq;
|
||||
import io.vavr.control.Option;
|
||||
@@ -13,23 +15,25 @@ import io.vavr.control.Try;
|
||||
import io.vavr.control.Validation;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.vavr.Person;
|
||||
import com.baeldung.vavr.PersonValidator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static io.vavr.API.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static io.vavr.API.$;
|
||||
import static io.vavr.API.Case;
|
||||
import static io.vavr.API.Match;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class VavrUnitTest {
|
||||
@Test
|
||||
public void givenList_whenSorts_thenCorrect() {
|
||||
List<Integer> sortedList = List.of(3, 2, 1)
|
||||
.sorted();
|
||||
.sorted();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -123,7 +127,7 @@ public class VavrUnitTest {
|
||||
@Test
|
||||
public void whenCreatesFunction_thenCorrect0() {
|
||||
Function0<String> getClazzName = () -> this.getClass()
|
||||
.getName();
|
||||
.getName();
|
||||
String clazzName = getClazzName.apply();
|
||||
assertEquals("com.baeldung.vavr.VavrUnitTest", clazzName);
|
||||
}
|
||||
@@ -257,7 +261,7 @@ public class VavrUnitTest {
|
||||
public void whenSumsJava8List_thenCorrect() {
|
||||
// Arrays.asList(1, 2, 3).stream().reduce((i, j) -> i + j);
|
||||
int sum = IntStream.of(1, 2, 3)
|
||||
.sum();
|
||||
.sum();
|
||||
assertEquals(6, sum);
|
||||
}
|
||||
|
||||
@@ -273,8 +277,8 @@ public class VavrUnitTest {
|
||||
@Test
|
||||
public void whenSumsVavrList_thenCorrect() {
|
||||
int sum = List.of(1, 2, 3)
|
||||
.sum()
|
||||
.intValue();
|
||||
.sum()
|
||||
.intValue();
|
||||
assertEquals(6, sum);
|
||||
}
|
||||
|
||||
@@ -307,21 +311,21 @@ public class VavrUnitTest {
|
||||
int input = 2;
|
||||
String output;
|
||||
switch (input) {
|
||||
case 0:
|
||||
output = "zero";
|
||||
break;
|
||||
case 1:
|
||||
output = "one";
|
||||
break;
|
||||
case 2:
|
||||
output = "two";
|
||||
break;
|
||||
case 3:
|
||||
output = "three";
|
||||
break;
|
||||
default:
|
||||
output = "unknown";
|
||||
break;
|
||||
case 0:
|
||||
output = "zero";
|
||||
break;
|
||||
case 1:
|
||||
output = "one";
|
||||
break;
|
||||
case 2:
|
||||
output = "two";
|
||||
break;
|
||||
case 3:
|
||||
output = "three";
|
||||
break;
|
||||
default:
|
||||
output = "unknown";
|
||||
break;
|
||||
}
|
||||
assertEquals("two", output);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
package com.baeldung.vavr.collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.vavr.Tuple;
|
||||
import io.vavr.Tuple2;
|
||||
import io.vavr.collection.Array;
|
||||
@@ -28,6 +16,17 @@ import io.vavr.collection.Stream;
|
||||
import io.vavr.collection.TreeMap;
|
||||
import io.vavr.collection.TreeSet;
|
||||
import io.vavr.collection.Vector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CollectionAPIUnitTest {
|
||||
|
||||
@@ -234,7 +233,7 @@ public class CollectionAPIUnitTest {
|
||||
.toJavaMap(i -> Tuple.of(i, Integer.valueOf(i)));
|
||||
assertEquals(new Integer(2), map.get("2"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenVavrList_whenCollected_thenCorrect() {
|
||||
java.util.Set<Integer> javaSet = List.of(1, 2, 3)
|
||||
|
||||
@@ -7,32 +7,32 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EitherUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenMarks_whenPassNumber_thenExpectNumber() {
|
||||
Either<String, Integer> result = EitherDemo.computeWithEither(100);
|
||||
int marks = result.right()
|
||||
.getOrElseThrow(x -> new IllegalStateException());
|
||||
@Test
|
||||
public void givenMarks_whenPassNumber_thenExpectNumber() {
|
||||
Either<String, Integer> result = EitherDemo.computeWithEither(100);
|
||||
int marks = result.right()
|
||||
.getOrElseThrow(x -> new IllegalStateException());
|
||||
|
||||
assertEquals(100, marks);
|
||||
}
|
||||
assertEquals(100, marks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMarks_whenFailNumber_thenExpectErrorMesssage() {
|
||||
Either<String, Integer> result = EitherDemo.computeWithEither(50);
|
||||
String error = result.left()
|
||||
@Test
|
||||
public void givenMarks_whenFailNumber_thenExpectErrorMesssage() {
|
||||
Either<String, Integer> result = EitherDemo.computeWithEither(50);
|
||||
String error = result.left()
|
||||
.getOrNull();
|
||||
|
||||
assertEquals("Marks not acceptable", error);
|
||||
}
|
||||
assertEquals("Marks not acceptable", error);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPassMarks_whenModified_thenExpectNumber() {
|
||||
Either<String, Integer> result = EitherDemo.computeWithEither(90);
|
||||
int marks = result.right()
|
||||
@Test
|
||||
public void givenPassMarks_whenModified_thenExpectNumber() {
|
||||
Either<String, Integer> result = EitherDemo.computeWithEither(90);
|
||||
int marks = result.right()
|
||||
.map(x -> x * 2)
|
||||
.get();
|
||||
|
||||
assertEquals(180, marks);
|
||||
}
|
||||
assertEquals(180, marks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,18 @@ package com.baeldung.vavr.exception.handling;
|
||||
import com.baeldung.vavr.exception.handling.client.ClientException;
|
||||
import com.baeldung.vavr.exception.handling.client.HttpClient;
|
||||
import com.baeldung.vavr.exception.handling.client.Response;
|
||||
import com.baeldung.vavr.exception.handling.VavrTry;
|
||||
|
||||
import io.vavr.collection.Stream;
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.vavr.API.*;
|
||||
import static io.vavr.API.$;
|
||||
import static io.vavr.API.Case;
|
||||
import static io.vavr.API.Match;
|
||||
import static io.vavr.Predicates.instanceOf;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class VavrTryUnitTest {
|
||||
|
||||
@@ -26,8 +28,8 @@ public class VavrTryUnitTest {
|
||||
//when
|
||||
Try<Response> response = new VavrTry(httpClient).getResponse();
|
||||
Integer chainedResult = response
|
||||
.map(this::actionThatTakesResponse)
|
||||
.getOrElse(defaultChainedResult);
|
||||
.map(this::actionThatTakesResponse)
|
||||
.getOrElse(defaultChainedResult);
|
||||
Stream<String> stream = response.toStream().map(it -> it.id);
|
||||
|
||||
//then
|
||||
@@ -49,8 +51,8 @@ public class VavrTryUnitTest {
|
||||
//when
|
||||
Try<Response> response = new VavrTry(httpClient).getResponse();
|
||||
Integer chainedResult = response
|
||||
.map(this::actionThatTakesResponse)
|
||||
.getOrElse(defaultChainedResult);
|
||||
.map(this::actionThatTakesResponse)
|
||||
.getOrElse(defaultChainedResult);
|
||||
Option<Response> optionalResponse = response.toOption();
|
||||
|
||||
//then
|
||||
@@ -70,9 +72,9 @@ public class VavrTryUnitTest {
|
||||
|
||||
//when
|
||||
Try<Response> recovered = new VavrTry(httpClient).getResponse()
|
||||
.recover(r -> Match(r).of(
|
||||
Case($(instanceOf(ClientException.class)), defaultResponse)
|
||||
));
|
||||
.recover(r -> Match(r).of(
|
||||
Case($(instanceOf(ClientException.class)), defaultResponse)
|
||||
));
|
||||
|
||||
//then
|
||||
assertTrue(recovered.isFailure());
|
||||
@@ -92,10 +94,10 @@ public class VavrTryUnitTest {
|
||||
|
||||
//when
|
||||
Try<Response> recovered = new VavrTry(httpClient).getResponse()
|
||||
.recover(r -> Match(r).of(
|
||||
Case($(instanceOf(ClientException.class)), defaultResponse),
|
||||
Case($(instanceOf(IllegalArgumentException.class)), defaultResponse)
|
||||
));
|
||||
.recover(r -> Match(r).of(
|
||||
Case($(instanceOf(ClientException.class)), defaultResponse),
|
||||
Case($(instanceOf(IllegalArgumentException.class)), defaultResponse)
|
||||
));
|
||||
|
||||
//then
|
||||
assertTrue(recovered.isSuccess());
|
||||
@@ -106,7 +108,7 @@ public class VavrTryUnitTest {
|
||||
return response.id.hashCode();
|
||||
}
|
||||
|
||||
public int actionThatTakesTryResponse(Try<Response> response, int defaultTransformation){
|
||||
public int actionThatTakesTryResponse(Try<Response> response, int defaultTransformation) {
|
||||
return response.transform(responses -> response.map(it -> it.id.hashCode()).getOrElse(defaultTransformation));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,18 +3,18 @@ package com.baeldung.vavr.repositories;
|
||||
import com.baeldung.Application;
|
||||
import com.baeldung.repositories.VavrUserRepository;
|
||||
import com.baeldung.vavr.User;
|
||||
|
||||
import io.vavr.collection.Seq;
|
||||
import io.vavr.control.Option;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
|
||||
Reference in New Issue
Block a user