BAEL-1020 -Introductionjukito (#2634)
* Examples for retrofit guide * Introduction to Jukito * class not needed * Changed to testing module
This commit is contained in:
parent
0dd6ddd137
commit
11f5ac7b44
|
@ -87,6 +87,12 @@
|
|||
<version>${jgotesting.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jukito</groupId>
|
||||
<artifactId>jukito</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.introductionjukito;
|
||||
|
||||
public interface Calculator {
|
||||
|
||||
public double add(double a, double b);
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.baeldung.introductionjukito;
|
||||
|
||||
public class ScientificCalculator extends SimpleCalculator {
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.introductionjukito;
|
||||
|
||||
public class SimpleCalculator implements Calculator {
|
||||
|
||||
@Override
|
||||
public double add(double a, double b) {
|
||||
return a+b;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.baeldung.introductionjukito;
|
||||
|
||||
import org.jukito.All;
|
||||
import org.jukito.JukitoModule;
|
||||
import org.jukito.JukitoRunner;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(JukitoRunner.class)
|
||||
public class CalculatorTest {
|
||||
|
||||
public static class Module extends JukitoModule {
|
||||
|
||||
@Override
|
||||
protected void configureTest() {
|
||||
bindMany(Calculator.class, SimpleCalculator.class,
|
||||
ScientificCalculator.class);
|
||||
bindManyInstances(AdditionTest.class, new AdditionTest(1, 1, 2),
|
||||
new AdditionTest(10, 10, 20),
|
||||
new AdditionTest(18, 24, 42));
|
||||
bindManyNamedInstances(Integer.class, "even", 2, 4, 6);
|
||||
bindManyNamedInstances(Integer.class, "odd", 1, 3, 5);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdditionTest {
|
||||
|
||||
int a;
|
||||
int b;
|
||||
int expected;
|
||||
|
||||
public AdditionTest(int a, int b, int expected) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.expected = expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoNumbers_WhenAdd_ThenSumBoth(@All Calculator calc) {
|
||||
double result = calc.add(1, 1);
|
||||
assertEquals(2, result, .1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoNumbers_WhenAdd_ThenSumBoth(@All Calculator calc,
|
||||
@All AdditionTest addTest) {
|
||||
double result = calc.add(addTest.a, addTest.b);
|
||||
assertEquals(addTest.expected, result, .1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEvenNumbers_whenPrint_thenOutput(@All("even") Integer i) {
|
||||
System.out.println("even " + i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenOddNumbers_whenPrint_thenOutput(@All("odd") Integer i) {
|
||||
System.out.println("odd " + i);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue