Skip to content

Commit 11f5ac7

Browse files
hugosama1pivovarit
authored andcommitted
BAEL-1020 -Introductionjukito (eugenp#2634)
* Examples for retrofit guide * Introduction to Jukito * class not needed * Changed to testing module
1 parent 0dd6ddd commit 11f5ac7

5 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎testing/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
<artifactId>jgotesting</artifactId>
8787
<version>${jgotesting.version}</version>
8888
<scope>test</scope>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.jukito</groupId>
92+
<artifactId>jukito</artifactId>
93+
<version>1.5</version>
94+
<scope>test</scope>
8995
</dependency>
9096
</dependencies>
9197
<build>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.introductionjukito;
2+
3+
public interface Calculator {
4+
5+
public double add(double a, double b);
6+
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.introductionjukito;
2+
3+
public class ScientificCalculator extends SimpleCalculator {
4+
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.introductionjukito;
2+
3+
public class SimpleCalculator implements Calculator {
4+
5+
@Override
6+
public double add(double a, double b) {
7+
return a+b;
8+
}
9+
10+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)