forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAEL-1020 -Introductionjukito (eugenp#2634)
* Examples for retrofit guide * Introduction to Jukito * class not needed * Changed to testing module
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
testing/src/main/java/com/baeldung/introductionjukito/Calculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
testing/src/main/java/com/baeldung/introductionjukito/ScientificCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.introductionjukito; | ||
|
||
public class ScientificCalculator extends SimpleCalculator { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
testing/src/main/java/com/baeldung/introductionjukito/SimpleCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
testing/src/test/java/com/baeldung/introductionjukito/CalculatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |