test0ster1


License

License

GroupId

GroupId

io.kevinlee
ArtifactId

ArtifactId

test0ster1
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

test0ster1
test0ster1
Project URL

Project URL

https://github.com/Kevin-Lee/test0ster1
Project Organization

Project Organization

io.kevinlee
Source Code Management

Source Code Management

https://github.com/Kevin-Lee/test0ster1

Download test0ster1

How to add to project

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

Dependencies

test (4)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.2
net.aichler : jupiter-interface jar 0.8.3
org.assertj : assertj-core jar 3.17.2
org.mockito : mockito-core jar 3.5.10

Project Modules

There are no modules declared in this project.

Test0ster1 (Testosterone)

Build Status Release Status

Download Maven Central

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.

Why is it called 'Testosterone'?

  1. It has 'test' in it Test-osterone.
  2. The binary numbers, 0 and 1, which have something to do with software, are found in 'testosterone' (Test-o-ster-one => Test-0-ster-1).
  3. The goal of this project is to provide a simple but powerful test framework just like testosterone makes men simple (or often called stupid :) ) and physically strong.

What does it look like?

  • test an expected exception
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"));
  }
  • test an expected exception and its cause
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"));
  }
  • test a void return type method (with Mockito)
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();
    });
  }
  • test a method which returns some result (with AssertJ)
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);
    });
  }

Get Test0ster1

Maven

<dependencies>
  ...

  <dependency>
    <groupId>io.kevinlee</groupId>
    <artifactId>test0ster1</artifactId>
    <version>0.2.0</version>
    <scope>test</scope>
  </dependency>

  ...
</dependencies>

Gradle

testCompile group: 'io.kevinlee', name: 'test0ster1', version: '0.2.0'

OR

testCompile "io.kevinlee:test0ster1:0.2.0"

Versions

Version
0.2.0
0.1.0