Test0ster1 (pronounced as 'Testosterone', Testosterone -> Test0sterone -> Test0ster(one == 1) -> Test0ster1 ) is a test framework which uses Java 8's new functional features (i.e. Lambda Expressions, Default Methods, etc.)
APACHE-2.0 License
Test0ster1 (pronounced as 'Testosterone', Testosterone -> Test0sterone -> Test0ster(one == 1) -> Test0ster1 ) is a simple test helper framework which uses Java 8's new functional features (i.e. Lambda Expressions, Default Methods, etc.) in order to provide simple and easy to use test tools.
import static testosterone.Testosterone.*;
import java.util.Objects;
import org.junit.Test;
@Test
public void testTestosteroneExpectingException() throws Exception {
/* Given */
final String value = null;
test("throwingNullTest",
"Objects.requireNonNull(null, \"message\") should throw NullPointerException.")
.when(() -> {
Objects.requireNonNull(value, "value cannot be null.");
})
.expect(throwing(NullPointerException.class)
.containsMessage("cannot be null"));
}
import static testosterone.Testosterone.*;
import org.junit.Test;
private void throwRuntimeException(final String value) {
if (value == null) {
throw new RuntimeException("test exception", new NullPointerException("value cannot be null."));
}
}
@Test
public void testTestosteroneExpectingExceptionWithCause() throws Exception {
/* Given */
final String value = null;
test("throwingNullTest2",
"throwRuntimeException(null) should throw RuntimeException caused by NullPointerException.")
.when(() ->
throwRuntimeException(value)
)
.expect(throwing(RuntimeException.class)
.hasMessage("test exception")
.containsMessage("test ")
.causedBy(NullPointerException.class)
.containsMessage("cannot be null"));
}
import static testosterone.Testosterone.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
@Test
public void testVerifyingVoidMethods() throws Exception {
/* given */
final Runnable innerRunnable1 = mock(Runnable.class);
final Runnable innerRunnable2 = mock(Runnable.class);
final Runnable runnable = () -> {
innerRunnable1.run();
innerRunnable2.run();
};
test("verifyVoidMethod",
"innerRunnable1.run() and innerRunnable2.run() should be invoked when runnable.run().")
.when(() -> {
runnable.run();
})
.then(() ->
verify(innerRunnable1, times(1)).run()
)
.then(() -> {
verify(innerRunnable2, times(1)).run();
});
}
import static testosterone.Testosterone.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
private String nullSafeTrim(final String value) {
return value == null ? "" : value.trim();
}
@Test
public void testNullSafeTrim() {
/* Given */
final String expected = "result";
final String input = " " + expected + " ";
test("assertThat",
"nullSafeTrim(\" result \") should return \"result\".")
.when(() ->
nullSafeTrim(input)
)
.then(actual ->
assertThat(actual.length()).isEqualTo(expected.length())
)
.then(actual -> {
assertThat(actual).isEqualTo(expected);
});
}
<dependencies>
...
<dependency>
<groupId>io.kevinlee</groupId>
<artifactId>test0ster1</artifactId>
<version>0.2.0</version>
<scope>test</scope>
</dependency>
...
</dependencies>
testCompile group: 'io.kevinlee', name: 'test0ster1', version: '0.2.0'
OR
testCompile "io.kevinlee:test0ster1:0.2.0"