From 8c0ce48aaee0bfa5b4cf772db424c9e6828eba87 Mon Sep 17 00:00:00 2001 From: Mansi Date: Tue, 22 Aug 2017 02:38:41 +0530 Subject: [PATCH] BAEL-1045 Lambda Behave (#2456) * Example Code For Evaluation Article This is an example code for the evaluation article on "Different Types of Bean Injection in Spring" * Added unit tests * Minor changes to application context * Removed code committed for evaluation article * BAEL-944 Demonstrating the problems with new Url pattern matching in Spring 5 * BAEL-944 Demonstrating the problems with new Url pattern matching in Spring 5 * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Code Formatting and solving build issue * BAEL-944 Resolving build issue due to change in Spring version * BAEL-944 Resolving build issue * BAEL-944 Formatting code * BAEL-944 Moving tests to correct package * BAEL-944 Moving tests to correct package * BAEL-944 Replacing @RequestMapping by @GetMapping * BAEL-944 Remove unnecessary attribute name, "value" in annotations * BAEL-79 Intro to Activiti with Spring * BAEL-79 Intro to Activiti with Spring * BAEL-79 Adding activiti module to the parent modules * BAEL-79 Using latest version * BAEL-79 Update Spring boot version that works with Activiti * BAEL-79 Replace RequestMapping with GetMapping * BAEL-79 Use Java 8 Syntax * BAEL-79 Formatting * BAEL-79 changed module name * BAEL-378 A Guide to Activiti with Java * BAEL-79 Fixed unit tests * BAEL-79 Simplified the process * BAEL-79 Fix test cases * BAEL-1045 Lambda Behave * BAEL-1045 Lambda Behave * BAEL-1045 Lambda Behave --- testing/pom.xml | 5 ++ .../com/baeldung/lambdabehave/Calculator.java | 24 +++++++++ .../baeldung/lambdabehave/CalculatorTest.java | 54 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 testing/src/main/java/com/baeldung/lambdabehave/Calculator.java create mode 100644 testing/src/test/java/com/baeldung/lambdabehave/CalculatorTest.java diff --git a/testing/pom.xml b/testing/pom.xml index bfd47dbc4a..72ec2b2f0c 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -13,6 +13,11 @@ + + com.insightfullogic + lambda-behave + 0.4 + com.google.guava guava diff --git a/testing/src/main/java/com/baeldung/lambdabehave/Calculator.java b/testing/src/main/java/com/baeldung/lambdabehave/Calculator.java new file mode 100644 index 0000000000..b194dce500 --- /dev/null +++ b/testing/src/main/java/com/baeldung/lambdabehave/Calculator.java @@ -0,0 +1,24 @@ +package com.baeldung.lambdabehave; + +public class Calculator { + + private int x; + private int y; + + Calculator(int x, int y) { + this.x = x; + this.y = y; + } + + public int add() { + return this.x + this.y; + } + + public int divide(int a, int b) { + return a / b; + } + + public int add(int a, int b) { + return a + b; + } +} diff --git a/testing/src/test/java/com/baeldung/lambdabehave/CalculatorTest.java b/testing/src/test/java/com/baeldung/lambdabehave/CalculatorTest.java new file mode 100644 index 0000000000..d179c6eb0e --- /dev/null +++ b/testing/src/test/java/com/baeldung/lambdabehave/CalculatorTest.java @@ -0,0 +1,54 @@ +package com.baeldung.lambdabehave; + +import com.insightfullogic.lambdabehave.JunitSuiteRunner; +import com.insightfullogic.lambdabehave.Suite; +import com.insightfullogic.lambdabehave.generators.Generator; +import com.insightfullogic.lambdabehave.generators.SourceGenerator; +import org.junit.runner.RunWith; + +@RunWith(JunitSuiteRunner.class) +public class CalculatorTest { + + private Calculator calculator; + + { + Suite.describe("Lambda behave example tests", it -> { + + it.isSetupWith(() -> { + calculator = new Calculator(1, 2); + }); + it.should("Add the given numbers", expect -> { + expect.that(calculator.add()).is(3); + }); + it.should("Throw an exception if divide by 0", expect -> { + expect.exception(ArithmeticException.class, () -> { + calculator.divide(1, 0); + }); + }); + it.uses(2, 3, 5) + .and(23, 10, 33) + .toShow("%d + %d = %d", (expect, a, b, c) -> { + expect.that(calculator.add(a, b)).is(c); + }); + it.requires(2) + .example(Generator.asciiStrings()) + .toShow("Reversing a String twice returns the original String", (expect, str) -> { + String same = new StringBuilder(str).reverse() + .reverse() + .toString(); + expect.that(same) + .isEqualTo(str); + }); + it.requires(2) + .withSource(SourceGenerator.deterministicNumbers(5626689007407L)) + .example(Generator.asciiStrings()) + .toShow("Reversing a String twice returns the original String", (expect, str) -> { + String same = new StringBuilder(str).reverse() + .reverse() + .toString(); + expect.that(same) + .isEqualTo(str); + }); + }); + } +}