diff --git a/README.md b/README.md deleted file mode 100644 index 566c5b5..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# springboot-study-orm-jpa -3-weeks ORM diff --git a/week1/week1/.gitignore b/demo2/.gitignore similarity index 100% rename from week1/week1/.gitignore rename to demo2/.gitignore diff --git a/week1/week1/build.gradle b/demo2/build.gradle similarity index 61% rename from week1/week1/build.gradle rename to demo2/build.gradle index 0f6d786..b51de33 100644 --- a/week1/week1/build.gradle +++ b/demo2/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'org.springframework.boot' version '2.5.2' + id 'org.springframework.boot' version '2.5.5' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } -group = 'com.livenow' +group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' @@ -20,11 +20,15 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.junit.jupiter:junit-jupiter:5.7.0' compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.h2database:h2' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.security:spring-security-test' } test { diff --git a/week1/week1/gradle/wrapper/gradle-wrapper.jar b/demo2/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from week1/week1/gradle/wrapper/gradle-wrapper.jar rename to demo2/gradle/wrapper/gradle-wrapper.jar diff --git a/week1/week1/gradle/wrapper/gradle-wrapper.properties b/demo2/gradle/wrapper/gradle-wrapper.properties similarity index 92% rename from week1/week1/gradle/wrapper/gradle-wrapper.properties rename to demo2/gradle/wrapper/gradle-wrapper.properties index 05679dc..ffed3a2 100644 --- a/week1/week1/gradle/wrapper/gradle-wrapper.properties +++ b/demo2/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/demo2/gradlew b/demo2/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/demo2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/week1/week1/gradlew.bat b/demo2/gradlew.bat similarity index 96% rename from week1/week1/gradlew.bat rename to demo2/gradlew.bat index ac1b06f..107acd3 100644 --- a/week1/week1/gradlew.bat +++ b/demo2/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/demo2/settings.gradle b/demo2/settings.gradle new file mode 100644 index 0000000..0365ca8 --- /dev/null +++ b/demo2/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'demo2' diff --git a/demo2/src/main/java/TddCalculator.java b/demo2/src/main/java/TddCalculator.java new file mode 100644 index 0000000..5702948 --- /dev/null +++ b/demo2/src/main/java/TddCalculator.java @@ -0,0 +1,31 @@ +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class TddCalculator { + private static final String DEFAULT_DELIMITER = "[,;]"; + + public int add(String text) { + if (text.isEmpty()) { + return 0; + } + return sum(toInteger(split(text))); + } + + private List toInteger(List values) { + return values.stream() + .map(Integer::parseInt) + .collect(Collectors.toList()); + } + + private List split(String text) { + return Arrays.stream(text.split(DEFAULT_DELIMITER)) + .collect(Collectors.toList()); + } + + private int sum(List values) { + return values.stream() + .mapToInt(Integer::intValue) + .sum(); + } +} \ No newline at end of file diff --git a/demo2/src/main/java/domain/Converter.java b/demo2/src/main/java/domain/Converter.java new file mode 100644 index 0000000..208cd6e --- /dev/null +++ b/demo2/src/main/java/domain/Converter.java @@ -0,0 +1,22 @@ +package domain; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class Converter { + + private Converter() { + + } + + public int toInteger(String value){ + return Integer.parseInt(value); + } + + public static List arrayToList(String[] numbers) { + return Arrays.stream(numbers) + .map(Number::new) + .collect(Collectors.toList()); + } +} diff --git a/demo2/src/main/java/domain/CustomDelimiter.java b/demo2/src/main/java/domain/CustomDelimiter.java new file mode 100644 index 0000000..f2bf16d --- /dev/null +++ b/demo2/src/main/java/domain/CustomDelimiter.java @@ -0,0 +1,8 @@ +package domain; + +public class CustomDelimiter extends Delimiter{ + + public CustomDelimiter(String custom) { + value = custom; + }; +} diff --git a/demo2/src/main/java/domain/Delimiter.java b/demo2/src/main/java/domain/Delimiter.java new file mode 100644 index 0000000..1d80d8d --- /dev/null +++ b/demo2/src/main/java/domain/Delimiter.java @@ -0,0 +1,14 @@ +package domain; + +public class Delimiter{ + + protected String value; + + public String[] split(String value) { + return value.split(value); + } + + public String getValue() { + return value; + } +} diff --git a/demo2/src/main/java/domain/ExistDelimiter.java b/demo2/src/main/java/domain/ExistDelimiter.java new file mode 100644 index 0000000..b5ae5c8 --- /dev/null +++ b/demo2/src/main/java/domain/ExistDelimiter.java @@ -0,0 +1,9 @@ +package domain; + +public class ExistDelimiter extends Delimiter{ + + public ExistDelimiter(){ + String EXIST_Delimiter=",|:"; + value=EXIST_Delimiter; + } +} diff --git a/demo2/src/main/java/domain/MultipleNumber.java b/demo2/src/main/java/domain/MultipleNumber.java new file mode 100644 index 0000000..56d54e5 --- /dev/null +++ b/demo2/src/main/java/domain/MultipleNumber.java @@ -0,0 +1,23 @@ +package domain; + +import java.util.ArrayList; +import java.util.List; + +public class MultipleNumber { + + public List numbers; + + public MultipleNumber(String[] numbers) { + this(Converter.arrayToList(numbers)); + } + + public MultipleNumber(List numbers) { + this.numbers = new ArrayList<>(numbers); + } + + public int sum() { + return numbers.stream() + .mapToInt(Number::getValue) + .sum(); + } +} diff --git a/demo2/src/main/java/domain/Number.java b/demo2/src/main/java/domain/Number.java new file mode 100644 index 0000000..34c4f8d --- /dev/null +++ b/demo2/src/main/java/domain/Number.java @@ -0,0 +1,27 @@ +package domain; + +public class Number { + + int value; + + public Number(int value){ + checkMinus(value); + this.value=value; + } + + public Number(String value){ + int iValue=Integer.parseInt(value); + checkMinus(iValue); + this.value=iValue; + } + + public void checkMinus(int value){ + if (value < 0){ + throw new RuntimeException("음수 감지"); + } + } + + public int getValue() { + return this.value; + } +} diff --git a/demo2/src/main/java/domain/StringCalculator.java b/demo2/src/main/java/domain/StringCalculator.java new file mode 100644 index 0000000..b12a2d2 --- /dev/null +++ b/demo2/src/main/java/domain/StringCalculator.java @@ -0,0 +1,4 @@ +package domain; + +public class StringCalculator { +} diff --git a/demo2/src/main/java/service/NewTddCalculator.java b/demo2/src/main/java/service/NewTddCalculator.java new file mode 100644 index 0000000..b02cf5a --- /dev/null +++ b/demo2/src/main/java/service/NewTddCalculator.java @@ -0,0 +1,51 @@ +package service; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class NewTddCalculator { + private static final String DEFAULT_DELIMETER = "[,;]"; + + public int add(String input) { + if (input.isEmpty()) { + return 0; + } + + Matcher m = Pattern.compile("//(.)\n(.*)").matcher(input); + + if (m.find()) { + String customDelimiter = m.group(1); + String[] tokens= m.group(2).split(customDelimiter); + return sum(toInt(tokens)); + } + return sum(toInt(split(input))); + } + + private int sum(int[] toInt) { + int value = 0; + for(int numbers : toInt){ + value += numbers; + } + return value; + } + + private String[] split(String input) { + return input.split(DEFAULT_DELIMETER); + } + + private int[] toInt(String[] input) { + int[] numbers = new int[input.length]; + for (int i = 0; i < input.length; i++) { + numbers[i] = toInts(input[i]); + } + return numbers; + } + + private int toInts(String number) { + int number1 = Integer.parseInt(number); + if (number1 < 0){ + throw new RuntimeException(); + } + return number1; + } + +} diff --git a/demo2/src/main/resources/application.properties b/demo2/src/main/resources/application.properties new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/demo2/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/demo2/src/test/java/TddCalculatorTest.java b/demo2/src/test/java/TddCalculatorTest.java new file mode 100644 index 0000000..9e65a66 --- /dev/null +++ b/demo2/src/test/java/TddCalculatorTest.java @@ -0,0 +1,82 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +@DisplayName("문자열 계산 테스트 with tdd") +class TddCalculatorTest { + + private TddCalculator tddCalculator; + + @BeforeEach + void setUp() { + tddCalculator = new TddCalculator(); + } + + @DisplayName("3을 입력시 3을 반환한다.") + @Test + void singleNumberWhenValue3() { + //given + final String number = "3"; + //when + int actual = tddCalculator.add(number); + //then + assertThat(actual).isEqualTo(3); + } + + @DisplayName("5를 입력시 5를 반환한다.") + @Test + void singleNumberWhenValue5() { + //given + final String number = "5"; + //when + int actual = tddCalculator.add(number); + //then + assertThat(actual).isEqualTo(5); + } + + @DisplayName("공백을 입력시 0을 반혼한다") + @Test + void convertToZero() { + //given + final String number = ""; + //when + final int actual = tddCalculator.add(number); + //then + assertThat(actual).isEqualTo(0); + } + + @DisplayName("쉼표 구분자를 입력시 값을 더한다") + @Test + void addWhenDefaultSeparator() { + //given + final String expect = "2,3"; + //when + final int actual = tddCalculator.add(expect); + //then + assertThat(actual).isEqualTo(5); + } + + @DisplayName("콜론 구분자를 입력시 값을 더한다") + @Test + void addWhenColonSeparator() { + //given + final String expect = "2;3"; + //when + final int actual = tddCalculator.add(expect); + //then + assertThat(actual).isEqualTo(5); + } + + @DisplayName("여러개의 콜론 구분자를 입력시 값을 더한다") + @Test + void addWhenColonSeparatorWhenMultiValue() { + //given + final String expect = "2;3;4"; + //when + final int actual = tddCalculator.add(expect); + //then + assertThat(actual).isEqualTo(9); + } +} \ No newline at end of file diff --git a/demo2/src/test/java/service/NewTddCalculatorTest.java b/demo2/src/test/java/service/NewTddCalculatorTest.java new file mode 100644 index 0000000..3450cfb --- /dev/null +++ b/demo2/src/test/java/service/NewTddCalculatorTest.java @@ -0,0 +1,90 @@ +package service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.regex.Pattern; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NewTddCalculatorTest { + + public static NewTddCalculator newTddCalculator; + + + @BeforeEach + void setUp() { + newTddCalculator = new NewTddCalculator(); + } + + @Test + public void emptyInputTest(){ + // given + String input = ""; + // when + int result = (int) newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(0); + } + + @Test + public void singleInputTest(){ + // given + String input = "3"; + // when + int result = newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(3); + } + + @Test + public void singleInputTest2(){ + // given + String input = "5"; + // when + int result = newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(5); + } + + @Test + public void doubleInputAddByCommaTest(){ + // given + final String input = "1,2"; + // when + final int result = newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(3); + } + + @Test + public void customInputAddByCommaTest(){ + // given + final String input = "1;2"; + // when + final int result =newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(3); + } + + @Test + public void checkMinusTest(){ + // given + final String input = "1;2;-1"; + // when + final int result =newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(4); + } + + @Test + public void customPatternTest(){ + // given + final String input = "//@\n1@2@3"; + // when + final int result =newTddCalculator.add(input); + // then + assertThat(result).isEqualTo(6); + } +} + diff --git a/mystudy b/mystudy new file mode 160000 index 0000000..6d1f22c --- /dev/null +++ b/mystudy @@ -0,0 +1 @@ +Subproject commit 6d1f22ca7aed3a4a437bc12eb7856af67c1f7ff0 diff --git a/study b/study new file mode 160000 index 0000000..5cb5841 --- /dev/null +++ b/study @@ -0,0 +1 @@ +Subproject commit 5cb5841ce7e84101ea388fe443ec513303212491 diff --git a/week1.key b/week1.key deleted file mode 100755 index 8469fef..0000000 Binary files a/week1.key and /dev/null differ diff --git a/week1/week1/gradlew b/week1/week1/gradlew deleted file mode 100755 index 22d2f57..0000000 --- a/week1/week1/gradlew +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG=$(dirname "$PRG")"/$link" - fi -done -SAVED="$(pwd)" -cd "$(dirname \"$PRG\")/" >/dev/null -APP_HOME="$(pwd -P)" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=$(basename "$0") - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn() { - echo "$*" -} - -die() { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$(uname)" in -CYGWIN*) - cygwin=true - ;; -Darwin*) - darwin=true - ;; -MSYS* | MINGW*) - msys=true - ;; -NONSTOP*) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ]; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then - MAX_FD_LIMIT=$(ulimit -H -n) - if [ $? -eq 0 ]; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ]; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ]; then - APP_HOME=$(cygpath --path --mixed "$APP_HOME") - CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") - - JAVACMD=$(cygpath --unix "$JAVACMD") - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) - SEP="" - for dir in $ROOTDIRSRAW; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ]; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@"; do - CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) - CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition - eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg") - else - eval $(echo args$i)="\"$arg\"" - fi - i=$(expr $i + 1) - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save() { - for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/week1/week1/settings.gradle b/week1/week1/settings.gradle deleted file mode 100644 index c1ce79e..0000000 --- a/week1/week1/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'week1' diff --git a/week1/week1/src/main/java/com/livenow/week1/Week1Application.java b/week1/week1/src/main/java/com/livenow/week1/Week1Application.java deleted file mode 100644 index 9519a69..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/Week1Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.livenow.week1; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Week1Application { - - public static void main(String[] args) { - SpringApplication.run(Week1Application.class, args); - } - -} diff --git a/week1/week1/src/main/java/com/livenow/week1/controller/MemberController.java b/week1/week1/src/main/java/com/livenow/week1/controller/MemberController.java deleted file mode 100644 index 522a055..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/controller/MemberController.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.livenow.week1.controller; - -import com.livenow.week1.service.MemberService; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping("/api/v1/members") -public class MemberController { - - private final MemberService memberService; - - public MemberController(MemberService memberService) { - this.memberService = memberService; - } - - @PostMapping - @ResponseStatus(HttpStatus.OK) - public void saveMember(@RequestParam String name, @RequestParam int age) { - memberService.save(name, age); - } -} diff --git a/week1/week1/src/main/java/com/livenow/week1/controller/TeamController.java b/week1/week1/src/main/java/com/livenow/week1/controller/TeamController.java deleted file mode 100644 index b3b4f63..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/controller/TeamController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.livenow.week1.controller; - -import com.livenow.week1.service.TeamService; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping("/api/v1/teams") -public class TeamController { - - private final TeamService teamService; - - public TeamController(TeamService teamService) { - this.teamService = teamService; - } - - @PostMapping - @ResponseStatus(HttpStatus.OK) - public void save(@RequestParam String name) { - teamService.save(name); - } - - @PostMapping("/members") - @ResponseStatus(HttpStatus.OK) - public void addMember(@RequestParam Long teamId, @RequestParam Long memberId) { - teamService.addMember(teamId, memberId); - } -} diff --git a/week1/week1/src/main/java/com/livenow/week1/domain/Member.java b/week1/week1/src/main/java/com/livenow/week1/domain/Member.java deleted file mode 100644 index ee41696..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/domain/Member.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.livenow.week1.domain; - -import lombok.Getter; - -import javax.persistence.*; - -@Getter -@Entity -public class Member { - - @Id - @Column(name = "member_id") - private Long id; - - @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) - @JoinColumn(name = "team_id") - private Team team; - - private String name; - private int age; - - protected Member() { - } - - public Member(String name, int age) { - this(null, name, age, null); - } - - public Member(String name, int age, Team team) { - this(null, name, age, team); - } - - public Member(Long id, String name, int age) { - this(id, name, age, null); - } - - public Member(Long id, String name, int age, Team team) { - this.id = id; - this.name = name; - this.age = age; - this.team = team; - } - - public void changeTeam(Team team) { - this.team = team; - } -} diff --git a/week1/week1/src/main/java/com/livenow/week1/domain/MemberRepository.java b/week1/week1/src/main/java/com/livenow/week1/domain/MemberRepository.java deleted file mode 100644 index 99af4dc..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/domain/MemberRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.livenow.week1.domain; - -import org.springframework.stereotype.Repository; - -import javax.persistence.EntityManager; - -@Repository -public class MemberRepository { - - private final EntityManager em; - - public MemberRepository(EntityManager em) { - this.em = em; - } - - public void save(Member member) { - em.persist(member); - } - - public Member findById(Long id) { - return em.find(Member.class, id); - } -} - diff --git a/week1/week1/src/main/java/com/livenow/week1/domain/Team.java b/week1/week1/src/main/java/com/livenow/week1/domain/Team.java deleted file mode 100644 index 3e2b11b..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/domain/Team.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.livenow.week1.domain; - -import lombok.Getter; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import java.util.ArrayList; -import java.util.List; - -@Getter -@Entity -public class Team { - - @Id - @Column(name = "team_id") - private Long id; - private String name; - - @OneToMany(mappedBy = "team") - private List members = new ArrayList<>(); - - protected Team() { - } - - public Team(String name) { - this(null, name); - } - - public Team(Long id, String name) { - this.id = id; - this.name = name; - } -} diff --git a/week1/week1/src/main/java/com/livenow/week1/domain/TeamRepository.java b/week1/week1/src/main/java/com/livenow/week1/domain/TeamRepository.java deleted file mode 100644 index 474870e..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/domain/TeamRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.livenow.week1.domain; - -import org.springframework.stereotype.Repository; - -import javax.persistence.EntityManager; - -@Repository -public class TeamRepository { - - private final EntityManager em; - - public TeamRepository(EntityManager em) { - this.em = em; - } - - public void save(Team team) { - em.persist(team); - } - - public Team findById(Long id) { - return em.find(Team.class, id); - } -} diff --git a/week1/week1/src/main/java/com/livenow/week1/service/MemberService.java b/week1/week1/src/main/java/com/livenow/week1/service/MemberService.java deleted file mode 100644 index 7582526..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/service/MemberService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.livenow.week1.service; - -import com.livenow.week1.domain.Member; -import com.livenow.week1.domain.MemberRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -public class MemberService { - - private static Long AGE = 1L; - - private final MemberRepository memberRepository; - - public MemberService(MemberRepository memberRepository) { - this.memberRepository = memberRepository; - } - - @Transactional - public void save(String name, int age) { - Member member = new Member(AGE++, name, age); - memberRepository.save(member); - } -} diff --git a/week1/week1/src/main/java/com/livenow/week1/service/TeamService.java b/week1/week1/src/main/java/com/livenow/week1/service/TeamService.java deleted file mode 100644 index a5acedf..0000000 --- a/week1/week1/src/main/java/com/livenow/week1/service/TeamService.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.livenow.week1.service; - -import com.livenow.week1.domain.Member; -import com.livenow.week1.domain.MemberRepository; -import com.livenow.week1.domain.Team; -import com.livenow.week1.domain.TeamRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -public class TeamService { - - private static Long AGE = 1L; - - private final MemberRepository memberRepository; - private final TeamRepository teamRepository; - - public TeamService(MemberRepository memberRepository, TeamRepository teamRepository) { - this.memberRepository = memberRepository; - this.teamRepository = teamRepository; - } - - @Transactional - public void save(String name) { - Team team = new Team(AGE++, name); - teamRepository.save(team); - } - - @Transactional - public void addMember(Long teamId, Long memberId) { - Team team = teamRepository.findById(teamId); - Member member = memberRepository.findById(memberId); - member.changeTeam(team); - - team.getMembers().add(member); - } -} diff --git a/week1/week1/src/main/resources/application.yml b/week1/week1/src/main/resources/application.yml deleted file mode 100644 index 9a24886..0000000 --- a/week1/week1/src/main/resources/application.yml +++ /dev/null @@ -1,16 +0,0 @@ -spring: - datasource: - driver-class-name: org.h2.Driver - url: jdbc:h2:mem:test - username: sa - password: - - jpa: - hibernate: - ddl-auto: create - format_sql: true - show-sql: true - - h2: - console: - enabled: true diff --git a/week1/week1/src/test/java/com/livenow/week1/Week1ApplicationTests.java b/week1/week1/src/test/java/com/livenow/week1/Week1ApplicationTests.java deleted file mode 100644 index 3e04fc1..0000000 --- a/week1/week1/src/test/java/com/livenow/week1/Week1ApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.livenow.week1; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class Week1ApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/week1/week1/src/test/java/com/livenow/week1/domain/MemberRepositoryTest.java b/week1/week1/src/test/java/com/livenow/week1/domain/MemberRepositoryTest.java deleted file mode 100644 index 5554d24..0000000 --- a/week1/week1/src/test/java/com/livenow/week1/domain/MemberRepositoryTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.livenow.week1.domain; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; - -@SpringBootTest -@Transactional -class MemberRepositoryTest { - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private TeamRepository teamRepository; - - @Autowired - private EntityManager em; - - @Test - void memberGetTeam() { - //given - Member member = new Member(1L, "동현이 샛기", 3); - //when - memberRepository.save(member); - Member findMember = memberRepository.findById(1L); - //then - Assertions.assertThat(member.getId()).isEqualTo(findMember.getId()); - } - - - @Test - void memberGetTeam2() { - //given - Member member = new Member(1L, "동현이 샛기", 3); - Team team = new Team(1L, "배달의 민족"); - member.changeTeam(team); - //when - //teamRepository.save(team); - memberRepository.save(member); - Member findMember = memberRepository.findById(1L); - em.flush(); - em.clear(); - Team team2 = teamRepository.findById(1L); - //then - Assertions.assertThat(findMember.getTeam()).isNotNull(); - Assertions.assertThat(team2).isNotNull(); - } -} \ No newline at end of file