Skip to content

Instantly share code, notes, and snippets.

@SiAust
Created March 16, 2021 10:07
Show Gist options
  • Save SiAust/f6c6d53e5138444112a7c4af7be7d839 to your computer and use it in GitHub Desktop.
Save SiAust/f6c6d53e5138444112a7c4af7be7d839 to your computer and use it in GitHub Desktop.
Simple example of JUnit
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
public class JUnitTest {
@Test
public void CalculatorTest() {
Calculator calculator = new Calculator();
assertEquals(10, calculator.sum("1234"));
}
}
class Calculator {
public int sum(String digits) {
return Arrays.stream(digits.split("")).map(Integer::valueOf)
.reduce(Integer::sum).get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment