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
This commit is contained in:
Mansi 2017-08-22 02:38:41 +05:30 committed by Grzegorz Piwowarek
parent 822e8682b6
commit 8c0ce48aae
3 changed files with 83 additions and 0 deletions

View File

@ -13,6 +13,11 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>com.insightfullogic</groupId>
<artifactId>lambda-behave</artifactId>
<version>0.4</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>

View File

@ -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;
}
}

View File

@ -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);
});
});
}
}