Skip to content

Instantly share code, notes, and snippets.

View sullivan-'s full-sized avatar

John Sullivan sullivan-

View GitHub Profile
package org.broadinstitute.toolkit
package core.domain.analysis
/**
* Maintains sequences of singleton column view policies by the policy
* type. Also contains the composite column view policy that is used by
* default in an analysis.
*/
object ColumnViewPolicy {
trait Analysis {
val scoreColumns: Seq[ScoreColumn] = Seq()
}
trait AnalysisColumn
trait ScoreColumn extends AnalysisColumn
trait RawDataScoreColumn extends ScoreColumn
trait ComputedScoreColumn extends ScoreColumn {
val parentColumns: Seq[ScoreColumn] = Seq()
}
case class User(username: String, password: String)
trait UserRepositoryComponent {
val userRepository: UserRepository
class UserRepository {
def create(user: User): Unit = println("create " + user)
}
}
trait UserServiceComponent {
case class User(username: String, password: String)
trait UserRepositoryComponent {
val userRepository: UserRepository
trait UserRepository {
def create(user: User): Unit
}
}
trait UserRepositoryComponentImpl extends UserRepositoryComponent {
// libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test"
//
// libraryDependencies += "org.easymock" % "easymockclassextension" % "3.1" % "test"
import org.scalatest.mock.EasyMockSugar
trait ComponentRegistryMock extends ComponentRegistry with EasyMockSugar {
val userService = mock[UserService]
val userRepository = mock[UserRepository]
}
import org.easymock.EasyMock.reset
import org.scalatest.FlatSpec
class UserServiceSpec
extends FlatSpec
with ComponentRegistryMock
with UserServiceComponentImpl {
behavior of "UserServiceImpl.create"
trait RepositoryComponent
extends ProjectRepositoryComponent
with UserRepositoryComponent
trait RepositoryComponentImpl
extends RepositoryComponent
with ProjectRepositoryComponentImpl
with UserRepositoryComponentImpl
trait ServiceComponent
trait ProjectRepositoryComponent {
val projectRepository: ProjectRepository
trait ProjectRepository {
def create(project: Project): Unit
}
}
trait ProjectRepositoryComponentImpl extends ProjectRepositoryComponent {
self: UserServiceComponent => // <= does not compile!
override val projectRepository: ProjectRepository = new ProjectRepositoryImpl
trait RepositoryComponentImpl
extends RepositoryComponent
with ProjectRepositoryComponentImpl
with UserRepositoryComponentImpl {
self: ServiceComponent =>
}
trait RepositoryComponentImpl
extends RepositoryComponent
with ProjectRepositoryComponentImpl
with UserRepositoryComponentImpl {
// do not self-type to ServiceComponent here as it breaks design constraint!
}