BAEL-1020 -Introductionjukito (#2634)

* Examples for retrofit guide

* Introduction to Jukito

* class not needed

* Changed to testing module
This commit is contained in:
hugosama1 2017-09-19 00:11:35 -06:00 committed by Grzegorz Piwowarek
parent 0dd6ddd137
commit 11f5ac7b44
5 changed files with 90 additions and 0 deletions

View File

@ -86,6 +86,12 @@
<artifactId>jgotesting</artifactId> <artifactId>jgotesting</artifactId>
<version>${jgotesting.version}</version> <version>${jgotesting.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jukito</groupId>
<artifactId>jukito</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,7 @@
package com.baeldung.introductionjukito;
public interface Calculator {
public double add(double a, double b);
}

View File

@ -0,0 +1,5 @@
package com.baeldung.introductionjukito;
public class ScientificCalculator extends SimpleCalculator {
}

View File

@ -0,0 +1,10 @@
package com.baeldung.introductionjukito;
public class SimpleCalculator implements Calculator {
@Override
public double add(double a, double b) {
return a+b;
}
}

View File

@ -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);
}
}