io.backpackcloud:spectaculous

Spectaculous is a framework that helps you creating Specs with a fluent interface.

License

License

GroupId

GroupId

io.backpackcloud
ArtifactId

ArtifactId

spectaculous
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Spectaculous is a framework that helps you creating Specs with a fluent interface.
Project URL

Project URL

https://github.com/backpackcloud/spectaculous
Source Code Management

Source Code Management

https://github.com/backpackcloud/spectaculous

Download spectaculous

How to add to project

<!-- https://jarcasting.com/artifacts/io.backpackcloud/spectaculous/ -->
<dependency>
    <groupId>io.backpackcloud</groupId>
    <artifactId>spectaculous</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.backpackcloud/spectaculous/
implementation 'io.backpackcloud:spectaculous:0.2.0'
// https://jarcasting.com/artifacts/io.backpackcloud/spectaculous/
implementation ("io.backpackcloud:spectaculous:0.2.0")
'io.backpackcloud:spectaculous:jar:0.2.0'
<dependency org="io.backpackcloud" name="spectaculous" rev="0.2.0">
  <artifact name="spectaculous" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.backpackcloud', module='spectaculous', version='0.2.0')
)
libraryDependencies += "io.backpackcloud" % "spectaculous" % "0.2.0"
[io.backpackcloud/spectaculous "0.2.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.hamcrest : hamcrest jar 2.2

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.5.2
org.mockito : mockito-core jar 3.2.4

Project Modules

There are no modules declared in this project.

Spectaculous

Spectaculous is a framework that helps you defining specifications with the help of a fluent interface. The idea behind is to put some functional interfaces introduced in Java 8 together to provide a beautiful way to define specifications in pure Java code. Its main use is for testing but you can use for any purpose that requires writing a specification.

How To Build

Just make sure you have Maven and run the command maven package. To install spectaculous on your local maven repository, use the command maven install. Spectaculous is also in Maven Central. Just use the following groupId and artifactId to declare the dependency:

  • groupId: io.backpackcloud
  • artifactId: spectaculous

Defining Specifications

To define a new specification, use the Spec class. It defines an entry point to the fluent interface:

Account myAccount = new Account(500);

Spec.describe("Money transfer")
  .given(new Account(500))
  .expect(500).from(Account::balance)
  
  .then(account -> account.transfer(100).to(myAccount))

  .expect(400).from(Account::balance)
  
  .because("Accounts should have enough funds to make a transfer")
  .expect(InsufficientBalanceException.class).when(account -> account.transfer(1000).to(myAccount))
Spec.describe("A trader is alerted of status")
  .given(newStock("STK").withThresholdOf(15.0))

  .then(tradeAt(5.0))
  
  .expect("OFF").from(alert())

  .then(tradeAt(16.0))
  .expect("ON").from(alert());
Spec.describe(Address.class)
    .given(Address.fromString("bar"))
    .because("The default channel should be assigned if not provided")
    .expect("default").from(Address::channel)
    .expect("bar").from(Address::id)

    .given(Address.fromString("foo:bar"))
    .because("The pattern channel:id should be used to parse the address")
    .expect("foo").from(Address::channel)
    .expect("bar").from(Address::id)

    .because("Addresses from string should have at least an ID")
    .expect(UnbelievableException.class).when(() -> Address.fromString(""))
    .expect(UnbelievableException.class).when(() -> Address.fromString(null));
io.backpackcloud

Backpack Cloud

Ideas worth packing!

Versions

Version
0.2.0
0.1.1