Skip to content

Update refactored sample code for 依存性の注入によるリファクタリング #1475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package domain

trait UserService {
self: PasswordService with UserRepository =>

val maxNameLength = 32

def register(name: String, rawPassword: String): User

def login(name: String, rawPassword: String): User

}

class UserServiceImpl extends UserService { self: UserRepository with PasswordService =>
def register(name: String, rawPassword: String): User = {
if (name.length > maxNameLength) {
throw new Exception("Too long name!")
Expand All @@ -26,5 +32,3 @@ trait UserService {
}
}
}

class UserServiceImpl extends UserService with PasswordServiceImpl with UserRepositoryImpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalatest.wordspec.AnyWordSpec
class UserServiceSpec extends AnyWordSpec {
val user = User(1, "test_name", "test_password")

val sut = new UserService with PasswordServiceImpl with UserRepository {
val sut = new UserServiceImpl with PasswordServiceImpl with UserRepository {
def find(id: Long): Option[domain.User] = Some(user)
def find(name: String): Option[domain.User] = Some(user)
def insert(user: domain.User): domain.User = user
Expand Down