Skip to content

Commit

Permalink
BAEL-1020 -Introductionjukito (eugenp#2634)
Browse files Browse the repository at this point in the history
* Examples for retrofit guide

* Introduction to Jukito

* class not needed

* Changed to testing module
  • Loading branch information
hugosama1 authored and pivovarit committed Sep 19, 2017
1 parent 0dd6ddd commit 11f5ac7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
6 changes: 6 additions & 0 deletions testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
<artifactId>jgotesting</artifactId>
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.baeldung.introductionjukito;

public interface Calculator {

public double add(double a, double b);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.introductionjukito;

public class ScientificCalculator extends SimpleCalculator {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.baeldung.introductionjukito;

public class SimpleCalculator implements Calculator {

@Override
public double add(double a, double b) {
return a+b;
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 11f5ac7

Please sign in to comment.