Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 2.06 KB

README.md

File metadata and controls

51 lines (37 loc) · 2.06 KB

Scientist for Java

Actions Status

A quick and nasty port of the Scientist.net (commit #bf32144) project, which itself is a port of the original Scientist library. Credits for good things should go to these guys, while blame for bugs belongs solely to me -- not legally though, see LICENSE ;)

Why a port of a port?

The code-base I work with in my day job is a Java back-end with a .NET desktop client, and having the same Science API on both sides made good sense.

Usage

The architecture from Scientist.NET has been kept with the exception of asynchronous experiments. Java doesn't have the same asynch / await language features, so that functionality would require some extra thought. Another difference is that "Try()" is now "attempt()".

Example:

public class ScientistTest {
	boolean isNotCollaborator(String name) { return true; }
	boolean isHasAccess(String name) { return true; }

	@Test
	public void testScience() {
		final String user = "jdoe";
		boolean isCollaborator = Scientist.science("widget-permissions", experiment -> {
			experiment.use(() -> isNotCollaborator(user));
			experiment.attempt(() -> isHasAccess(user));
			experiment.setThrowOnMismatches(true);
		});

		assertTrue(isCollaborator);
	}
}    

See the original .NET documentation for a full description of how to setup experiments (the API in Java is the same).

Lombok

This project uses Project Lombok for boilerplate code. It will compile fine with Maven, but if you want to edit the sources in an IDE, you will need the Project Lombok plugin.