-
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.
- Loading branch information
Showing
5 changed files
with
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package chap02; | ||
|
||
public class Calculator { | ||
|
||
public static int plus(int a1, int a2) { | ||
return a1+a2; | ||
} | ||
} |
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,15 @@ | ||
package chap02; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CalculatorTest { | ||
|
||
@Test | ||
void plus(){ | ||
int result = Calculator.plus(1, 2); | ||
assertEquals(3, result); | ||
assertEquals(5, Calculator.plus(4,1)); | ||
} | ||
} |
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 chap02; | ||
|
||
public enum PasswordStrength { | ||
NORMAL, STRONG | ||
} |
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,8 @@ | ||
package chap02; | ||
|
||
public class PasswordStrengthMeter { | ||
public PasswordStrength meter(String s) { | ||
if(s.length() < 8) return PasswordStrength.NORMAL; | ||
return PasswordStrength.STRONG; | ||
} | ||
} |
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,25 @@ | ||
package chap02; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class PasswordStrengthMeterTest { | ||
@Test | ||
void meetsAllCriteria_Then_Strong(){ | ||
PasswordStrengthMeter meter = new PasswordStrengthMeter(); | ||
PasswordStrength result = meter.meter("abcd!@AB"); | ||
assertEquals(PasswordStrength.STRONG, result); | ||
PasswordStrength result2 = meter.meter("abcd!Add"); | ||
assertEquals(PasswordStrength.STRONG, result2); | ||
} | ||
|
||
@Test | ||
void meetsOtherCriteria_except_for_Length_Then_Normal(){ | ||
PasswordStrengthMeter meter = new PasswordStrengthMeter(); | ||
PasswordStrength result = meter.meter("abcd!@A"); | ||
assertEquals(PasswordStrength.NORMAL, result); | ||
PasswordStrength result2 = meter.meter("abcd!c"); | ||
assertEquals(PasswordStrength.NORMAL, result2); | ||
} | ||
} |