|
| 1 | +package com.baeldung.introductionjukito; |
| 2 | + |
| 3 | +import org.jukito.All; |
| 4 | +import org.jukito.JukitoModule; |
| 5 | +import org.jukito.JukitoRunner; |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.runner.RunWith; |
| 8 | +import static org.junit.Assert.*; |
| 9 | + |
| 10 | +@RunWith(JukitoRunner.class) |
| 11 | +public class CalculatorTest { |
| 12 | + |
| 13 | + public static class Module extends JukitoModule { |
| 14 | + |
| 15 | + @Override |
| 16 | + protected void configureTest() { |
| 17 | + bindMany(Calculator.class, SimpleCalculator.class, |
| 18 | + ScientificCalculator.class); |
| 19 | + bindManyInstances(AdditionTest.class, new AdditionTest(1, 1, 2), |
| 20 | + new AdditionTest(10, 10, 20), |
| 21 | + new AdditionTest(18, 24, 42)); |
| 22 | + bindManyNamedInstances(Integer.class, "even", 2, 4, 6); |
| 23 | + bindManyNamedInstances(Integer.class, "odd", 1, 3, 5); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public static class AdditionTest { |
| 28 | + |
| 29 | + int a; |
| 30 | + int b; |
| 31 | + int expected; |
| 32 | + |
| 33 | + public AdditionTest(int a, int b, int expected) { |
| 34 | + this.a = a; |
| 35 | + this.b = b; |
| 36 | + this.expected = expected; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void givenTwoNumbers_WhenAdd_ThenSumBoth(@All Calculator calc) { |
| 42 | + double result = calc.add(1, 1); |
| 43 | + assertEquals(2, result, .1); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void givenTwoNumbers_WhenAdd_ThenSumBoth(@All Calculator calc, |
| 48 | + @All AdditionTest addTest) { |
| 49 | + double result = calc.add(addTest.a, addTest.b); |
| 50 | + assertEquals(addTest.expected, result, .1); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void givenEvenNumbers_whenPrint_thenOutput(@All("even") Integer i) { |
| 55 | + System.out.println("even " + i); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void givenOddNumbers_whenPrint_thenOutput(@All("odd") Integer i) { |
| 60 | + System.out.println("odd " + i); |
| 61 | + } |
| 62 | +} |
0 commit comments