From 64a65e1ea6879badb98cc50cea91f0c4a1727bb0 Mon Sep 17 00:00:00 2001 From: sangminee Date: Sun, 8 Jan 2023 23:02:51 +0900 Subject: [PATCH] =?UTF-8?q?chap02.=20tdd=EB=9E=80=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/chap02/Calculator.java | 8 ++++++ src/test/java/chap02/CalculatorTest.java | 15 +++++++++++ src/test/java/chap02/PasswordStrength.java | 5 ++++ .../java/chap02/PasswordStrengthMeter.java | 8 ++++++ .../chap02/PasswordStrengthMeterTest.java | 25 +++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 src/main/java/chap02/Calculator.java create mode 100644 src/test/java/chap02/CalculatorTest.java create mode 100644 src/test/java/chap02/PasswordStrength.java create mode 100644 src/test/java/chap02/PasswordStrengthMeter.java create mode 100644 src/test/java/chap02/PasswordStrengthMeterTest.java diff --git a/src/main/java/chap02/Calculator.java b/src/main/java/chap02/Calculator.java new file mode 100644 index 0000000..150ae04 --- /dev/null +++ b/src/main/java/chap02/Calculator.java @@ -0,0 +1,8 @@ +package chap02; + +public class Calculator { + + public static int plus(int a1, int a2) { + return a1+a2; + } +} diff --git a/src/test/java/chap02/CalculatorTest.java b/src/test/java/chap02/CalculatorTest.java new file mode 100644 index 0000000..2c3a681 --- /dev/null +++ b/src/test/java/chap02/CalculatorTest.java @@ -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)); + } +} diff --git a/src/test/java/chap02/PasswordStrength.java b/src/test/java/chap02/PasswordStrength.java new file mode 100644 index 0000000..195ac94 --- /dev/null +++ b/src/test/java/chap02/PasswordStrength.java @@ -0,0 +1,5 @@ +package chap02; + +public enum PasswordStrength { + NORMAL, STRONG +} diff --git a/src/test/java/chap02/PasswordStrengthMeter.java b/src/test/java/chap02/PasswordStrengthMeter.java new file mode 100644 index 0000000..45e43f4 --- /dev/null +++ b/src/test/java/chap02/PasswordStrengthMeter.java @@ -0,0 +1,8 @@ +package chap02; + +public class PasswordStrengthMeter { + public PasswordStrength meter(String s) { + if(s.length() < 8) return PasswordStrength.NORMAL; + return PasswordStrength.STRONG; + } +} diff --git a/src/test/java/chap02/PasswordStrengthMeterTest.java b/src/test/java/chap02/PasswordStrengthMeterTest.java new file mode 100644 index 0000000..599ca46 --- /dev/null +++ b/src/test/java/chap02/PasswordStrengthMeterTest.java @@ -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); + } +}