BAEL-6228-Pipeline-Design-Pattern-in-Java (#13547)
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.pipeline;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.baeldung.pipeline.pipes.Pipe;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PipeUnitTest {
|
||||
|
||||
@Test
|
||||
void simplePipeTest() {
|
||||
Pipe<Integer, Integer> square = s -> s * s;
|
||||
Pipe<Integer, Integer> half = s -> s / 2;
|
||||
Pipe<Integer, String> toString = Object::toString;
|
||||
Pipe<Integer, String> pipeline = square.add(half).add(toString);
|
||||
String result = pipeline.process(5);
|
||||
String expected = "12";
|
||||
assertThat(result).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.pipeline;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.baeldung.pipeline.immutable.Pipe;
|
||||
import com.baeldung.pipeline.immutable.Pipeline;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PipelineUnitTest {
|
||||
|
||||
@Test
|
||||
void simplePipelineTest() {
|
||||
Pipe<Integer, Integer> square = s -> s * s;
|
||||
Pipe<Integer, Integer> half = s -> s / 2;
|
||||
Pipe<Integer, String> toString = Object::toString;
|
||||
Pipeline<Integer, Integer> squarePipeline = Pipeline.of(square);
|
||||
Pipeline<Integer, Integer> squareAndHalfPipeline = squarePipeline.withNextPipe(half);
|
||||
Pipeline<Integer, String> squareHalfAndStringPipeline = squareAndHalfPipeline.withNextPipe(toString);
|
||||
|
||||
String result = squareHalfAndStringPipeline.process(5);
|
||||
String expected = "12";
|
||||
assertThat(result).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user