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
package org.scalabound.scatdd.scalacheck | |
import org.scalabound.scatdd.FizzBuzz | |
import org.scalacheck.ConsoleReporter.testReport | |
import org.scalacheck.Prop.forAll | |
import org.scalacheck.Prop.propBoolean | |
import org.scalacheck.ConsoleReporter | |
import org.scalacheck.Test | |
object FizzBuzzScalaCheck { |
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
package org.scalabound.scatdd.scalatest | |
import org.junit.runner.RunWith | |
import org.scalatest.FunSpec | |
import org.scalatest.junit.JUnitRunner | |
import org.scalabound.scatdd.FizzBuzz | |
@RunWith(classOf[JUnitRunner]) | |
class FizzBuzzScalaTest extends FunSpec { |
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
package org.scalabound.scatdd.specs2 | |
import org.scalabound.scatdd.FizzBuzz | |
import org.junit.runner.RunWith | |
import org.specs2.runner.JUnitRunner | |
// package unitTest { |> Scala IDE will not pick the class up as runnable if I sub-package it like this :-( | |
@RunWith(classOf[JUnitRunner]) | |
class FizzBuzzJUnitSpec extends org.specs2.mutable.Specification { | |
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
package org.scalabound.scatdd | |
object FizzBuzz { | |
def eval(x: Int) = (x % 3, x % 5, x) match { | |
case(0, 0, _) => "FizzBuzz" | |
case(0, _, _) => "Fizz" | |
case(_, 0, _) => "Buzz" | |
case _ => "" + x | |
} |
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
package org.scalabound.scatdd; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
import org.scalabound.scatdd.FizzBuzz; | |
public class FizzBuzzJUnitTest { |
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
mvn archetype:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple | |
mvn compile | |
mvn exec:java -Dexec.mainClass="some.path.to.Main" -Dexec.args="arg0 arg1 arg2" |
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
package output | |
import javax.xml.bind.{ Marshaller, JAXBContext } | |
import javax.xml.bind.annotation._ | |
import javax.xml.bind.util.JAXBSource | |
import javax.xml.transform.Source | |
import javax.xml.ws.{ Endpoint, Provider, ServiceMode, WebServiceContext, WebServiceProvider } | |
import javax.xml.ws.http.HTTPBinding | |
import javax.xml.ws.handler.MessageContext | |
import javax.annotation.Resource |
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
case class Person(val firstName: String, val lastName: String, val age: Int, val email: String) { | |
def update(firstName: String = firstName, lastName: String = lastName, age: Int = age, email: String = email) : Person = { | |
Person(firstName, lastName, age, email) | |
} | |
} | |
val seedPerson = Person("A", "B", 1, "[email protected]") | |
println(seedPerson) | |
val updatedPerson = seedPerson update (age = 100, firstName = "Z") |
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
class ReifiedManifest[T <: Any : Manifest](value: T) { | |
val m = manifest[T] // So at this point we have the manifest for the Parameterized type | |
// At which point we could either do an if() expression on what type is contained in our manifest | |
if (m equals manifest[String]) { | |
println("The manifest contains a String") | |
} else if (m <:< manifest[AnyVal]) { // A subtype check using the <:< operation on the Manifest trait | |
println("The manifest contains a subtype of AnyVal") | |
} else if (m <:< manifest[AnyRef]) { |
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
case class PrintFormatter[T](item : T) { | |
def formatString(implicit evidence: T =:= String) = { // Will only work for String PrintFormatters | |
println("STRING specialised printformatting...") | |
} | |
def formatPrimitive(implicit evidence: T <:< AnyVal) = { // Will only work for Primitive PrintFormatters | |
println("WRAPPED PRIMITIVE specialised printformatting...") | |
} | |
} | |
val stringPrintFormatter = PrintFormatter("String to format...") |
NewerOlder