Skip to content

mlnkrish/shouldJ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShouldJ

Fluent unit testing for java.

Using with Maven

Add the following to your pom.xml

<repositories>
    <repository>
        <id>shouldj-releases</id>
        <url>https://raw.github.com/mlnkrish/shouldJ/mvn-repo</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>name.mlnkrishnan.shouldJ</groupId>
        <artifactId>shouldJ</artifactId>
        <version>2.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Basic Usage

it(2).shouldBe(5);
it(2).shouldNotBe(5);

Object obj = null;
it(obj).shouldBeNull();

DummyType obj = new DummyType();
it(obj).shouldBeOfType(DummyType.class);

it(new Boolean(true)).shouldBeTrue();
it(false).shouldBeFalse();

Collections

List<Integer> integers = Arrays.asList(1, 2, 3, 5);
it(integers)
        .shouldHave(3).at(2)
        .shouldNotHave(4)
        .shouldHave(1).at(0)
        .shouldHave(2).at(1)
        .shouldHave(5);

List<DummyType> dummyTypes = Arrays.asList(new DummyType(1, 'a'), new DummyType(2, 'b'));

it(dummyTypes)
        .shouldNotHave(new P<DummyType>() {
            @Override
            public boolean is(DummyType obj) {
                return obj.aNum == 3;
            }
        })
        .shouldNotHave(new P<DummyType>() {
            @Override
            public boolean is(DummyType obj) {
                return obj.aChar == 'K';
            }
        });

Maps

final Object value1 = new Object();
final Object value2 = new Object();
Map<String, Object> stringObjectMap = new HashMap<String, Object>() {{
    put("key1", value1);
    put("key2", value2);
}};

it(stringObjectMap)
        .shouldHaveKey("key1").withValue(value1)
        .shouldHaveKey("key2").withValue(value2)
        .shouldNotHaveKey("unwantedKey");

Exceptions

it(new E() {
    @Override
    public void perform() {
        throw new NumberFormatException("i cant count");
    }
}).shouldThrow(NumberFormatException.class)
        .withMessage("i cant count");

See unit tests in this project for full api.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages