本文整理汇总了Scala中org.junit.Test类的典型用法代码示例。如果您正苦于以下问题:Scala Test类的具体用法?Scala Test怎么用?Scala Test使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Test类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SettingsTest
//设置package包名称以及导入依赖的类
package org.eck.entities
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
import com.google.appengine.tools.development.testing.LocalServiceTestHelper
import com.google.gson.JsonObject
import org.junit.{Assert, Test, After, Before}
class SettingsTest {
val helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig())
@Before def setUp(): Unit = helper.setUp
@After def tearDown() = helper.tearDown()
@Test
def testSetAndGetSetting = {
Settings.set("bla", "ble")
Assert.assertTrue(Settings.get("bla").isDefined)
Assert.assertEquals("ble", Settings.get("bla").get)
}
@Test
def testFromJson = {
val json = new JsonObject
json.addProperty("bla", "ble")
json.addProperty("ble", "bla")
Settings.fromJson(json)
Assert.assertTrue(Settings.get("bla").isDefined)
Assert.assertEquals("ble", Settings.get("bla").get)
Assert.assertTrue(Settings.get("ble").isDefined)
Assert.assertEquals("bla", Settings.get("ble").get)
}
@Test
def asJson = {
Settings.set("bla", "ble")
Settings.set("ble", "bla")
val json = Settings.asJson
Assert.assertEquals("ble", json.get("bla").getAsString)
Assert.assertEquals("bla", json.get("ble").getAsString)
}
}
示例2: es
//设置package包名称以及导入依赖的类
package fr.sysf.sample
import java.time.LocalDate
import fr.sysf.sample.domain.Customer
import fr.sysf.sample.service.CustomerRepository
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
@RunWith(classOf[SpringJUnit4ClassRunner])
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = Array(classOf[ApplicationConfig]))
//@ContextConfiguration(classes = Array(classOf[ApplicationConfig]))
class CustomerDataTest {
@Autowired
private val customerRepository: CustomerRepository = null
@Test
def getHello {
val customer = new Customer()
customer.firstName = "Anna"
customer.lastName = "Blum"
customer.birthDate = LocalDate.of(1965, 2, 7)
var request = customerRepository.save(customer)
// getAll before insert
assertThat(request).isNotNull
assertThat(request.createdDate).isNotNull
assertThat(request.updatedDate).isEqualTo(request.createdDate)
Assertions.assertThat(request.version).isEqualTo(0l)
request.city = "Paris"
request = customerRepository.save(request)
assertThat(request).isNotNull
Assertions.assertThat(request.createdDate).isNotNull
Assertions.assertThat(request.city).isEqualTo("Paris")
Assertions.assertThat(request.version).isEqualTo(1l)
}
}
示例3: SampleTest
//设置package包名称以及导入依赖的类
package io.github.nawforce.apexlink
import io.github.nawforce.ApexLink
import org.junit.{Assert, Test}
class SampleTest {
def sample(path : String) : Unit = {
Assert.assertEquals(0, ApexLink.run(Array(path)))
}
@Test def sample1() : Unit = {
sample("samples/forcedotcom-enterprise-architecture/src")
}
@Test def sample2() : Unit = {
sample("samples/forcedotcomlabs/chatter-game/src")
}
@Test def sample3() : Unit = {
sample("samples/SalesforceFoundation/Cumulus/src")
}
@Test def sample4() : Unit = {
sample("samples/SalesforceFoundation/HEDAP/src")
}
@Test def sample5() : Unit = {
sample("samples/SalesforceFoundation/CampaignTools/src")
}
@Test def sample6() : Unit = {
sample("samples/SalesforceFoundation/Volunteers-for-Salesforce/src")
}
@Test def sample7() : Unit = {
sample("samples/SalesforceFoundation/Relationships/src")
}
@Test def sample8() : Unit = {
sample("samples/SalesforceFoundation/Households/src")
}
@Test def sample9() : Unit = {
sample("samples/SalesforceFoundation/Recurring_Donations/src")
}
@Test def sample10() : Unit = {
sample("samples/SalesforceFoundation/Contacts_and_Organizations/src")
}
@Test def sample11() : Unit = {
sample("samples/SalesforceFoundation/Affiliations/src")
}
}
示例4: TestCaseClass
//设置package包名称以及导入依赖的类
package com.github.m50d.tailchase
import org.junit.Test
import shapeless._
import org.fest.assertions.Assertions.assertThat
case class TestCaseClass(f: Float, i: Int)
class UnfixTest {
@Test def unfixHelperHList(): Unit = {
val uh = the[UnfixHelper[Int, Any, String :: Int :: HNil]]
assertThat(uh.functor.map("Hello" :: 4 :: HNil)({ i: Int ? i / 2.0 })).isEqualTo("Hello" :: 2.0 :: HNil)
}
@Test def unfixHelperCaseClass(): Unit = {
val uh = the[UnfixHelper[Float, Any, TestCaseClass]]
assertThat(uh.functor.map(2f :: 4 :: HNil)(_.toString)).isEqualTo("2.0" :: 4 :: HNil)
}
@Test def unfixHelperSealedFamily(): Unit = {
val uh = the[UnfixHelper[Int, Any, Either[Int, String]] with NonTrivial]
assertThat(uh.fix(uh.functor.map(uh.unfix(Left(3))) { i: Int ? i + 1 })).isEqualTo(Left(4))
}
}
示例5: TailchaseTest
//设置package包名称以及导入依赖的类
package com.github.m50d.tailchase
import shapeless._
import syntax._
import org.junit.Test
import org.fest.assertions.Assertions.assertThat
class TailchaseTest {
@Test def cata(): Unit = {
val l = List(1, 2, 3, 4, 5)
assertThat(l.cata[Int] {
case Inl((x: Int) :: (y: Int) :: HNil) ? x + y
case Inr(_) ? 0
}).isEqualTo(15)
assertThat(l.cata[String] {
case Inl((x: Int) :: (y: String) :: HNil) ? y + x
case Inr(_) ? ""
}).isEqualTo("54321")
}
}
示例6: UtilsTest
//设置package包名称以及导入依赖的类
package com.uglylabs.httpduplicator
import org.junit.Test
import org.junit.Assert
class UtilsTest {
@Test
def testStr2HttpHost1() = {
val httpHost = HttpTarget("localhost")
Assert.assertEquals(80, httpHost.port)
Assert.assertEquals("http", httpHost.scheme)
Assert.assertEquals("localhost", httpHost.host)
}
@Test
def testStr2HttpHost2() = {
val httpHost = HttpTarget("https://localhost")
Assert.assertEquals(80, httpHost.port)
Assert.assertEquals("https", httpHost.scheme)
Assert.assertEquals("localhost", httpHost.host)
}
@Test
def testStr2HttpHost3() = {
val httpHost = HttpTarget("https://localhost:8443")
Assert.assertEquals(8443, httpHost.port)
Assert.assertEquals("https", httpHost.scheme)
Assert.assertEquals("localhost", httpHost.host)
}
// ignore path
@Test
def testStr2HttpHost4() = {
val httpHost = HttpTarget("https://localhost:8443/")
Assert.assertEquals(8443, httpHost.port)
Assert.assertEquals("https", httpHost.scheme)
Assert.assertEquals("localhost", httpHost.host)
}
}
示例7: Utf8ExtractorTest
//设置package包名称以及导入依赖的类
package sds.classfile.constant_pool
import org.junit.Test
import org.scalatest.Assertions
import sds.classfile.constant_pool.Utf8ValueExtractor.extract
class Utf8ExtractorTest extends Assertions {
val info: Array[ConstantInfo] = Array(
new Utf8Info("utf8"), new NumberInfo(ConstantInfo.INTEGER, 0), new NumberInfo(ConstantInfo.FLOAT, 0.0f),
new NumberInfo(ConstantInfo.LONG, 0L), new NumberInfo(ConstantInfo.DOUBLE, 0.0), new StringInfo(1),
new HandleInfo(1, 1), new InvokeDynamicInfo(1, 1), new ConstantInfoAdapter(),
new Utf8Info("java/lang/Object"), new ClassInfo(10), new MemberInfo(ConstantInfo.FIELD, 11, 1),
new Utf8Info("([[Ljava/util/List;Ljava/lang/System;)V"), new NameAndTypeInfo(1, 13), new TypeInfo(13)
)
@Test
def extractTest(): Unit = {
assert(extract(info(0), info) === "utf8")
assert(extract(info(1), info) === "0")
assert(extract(info(2), info) === "0.0")
assert(extract(info(3), info) === "0")
assert(extract(info(4), info) === "0.0")
assert(extract(info(5), info) === "utf8")
assert(extract(info(6), info) === "utf8")
assert(extract(info(7), info) === "utf8")
intercept[IllegalArgumentException] {
extract(info(8), info) === ""
}
assert(extract(info(10), info) === "Object")
assert(extract(info(11), info) === "Object.utf8")
assert(extract(info(13), info) === "utf8|(java.util.List[][],System)void")
assert(extract(info(14), info) === "(java.util.List[][],System)void")
}
}
示例8: AttributeInfoTest
//设置package包名称以及导入依赖的类
package sds.classfile.attribute
import org.junit.Test
import org.scalatest.Assertions
import sds.classfile.constant_pool._
class AttributeInfoTest extends Assertions {
val info: Array[ConstantInfo] = Array(
new Utf8Info("utf8"), new NumberInfo(ConstantInfo.INTEGER, 0), new NumberInfo(ConstantInfo.FLOAT, 0.0f),
new NumberInfo(ConstantInfo.LONG, 0L), new NumberInfo(ConstantInfo.DOUBLE, 0.0), new StringInfo(1),
new HandleInfo(1, 1), new InvokeDynamicInfo(1, 1), new ConstantInfoAdapter(),
new Utf8Info("java/lang/Object"), new ClassInfo(10), new MemberInfo(ConstantInfo.FIELD, 11, 1),
new Utf8Info("([[Ljava/util/List;Ljava/lang/System;)V"), new NameAndTypeInfo(1, 13), new TypeInfo(13)
)
@Test
def constantValueTest(): Unit = {
val const: ConstantValue = new ConstantValue("Hoge")
assert(const.toString() === "ConstantValue: Hoge")
}
@Test
def enclosingMethodTest(): Unit = {
val enc: EnclosingMethod = new EnclosingMethod(11, 13, info)
val enc2: EnclosingMethod = new EnclosingMethod(11, 0, info)
assert(enc.toString() === "EnclosingMethod: Object ([[Ljava/util/List;Ljava/lang/System;)V")
assert(enc2.toString() === "EnclosingMethod: Object ")
}
@Test
def signatureTest(): Unit = {
val sig: Signature = new Signature("hoge")
assert(sig.toString() === "Signature: hoge")
}
@Test
def sourceFileTest(): Unit = {
val source: SourceFile = new SourceFile("Hoge.java")
assert(source.toString() === "SourceFile: Hoge.java")
}
@Test
def deprecatedTest(): Unit = {
val dep: Deprecated = new Deprecated();
assert(dep.toString() === "Deprecated")
}
@Test
def syntheticTest(): Unit = {
val syn: Synthetic = new Synthetic();
assert(syn.toString() === "Synthetic")
}
}
示例9: MultiArgsStringBuilderTest
//设置package包名称以及导入依赖的类
package sds.util
import org.junit.Test
import org.scalatest.Assertions
import sds.util.{MultiArgsStringBuilder => Builder}
class MultiArgsStringBuilderTest extends Assertions {
@Test
def toStringTest() {
val b: Builder = new Builder()
assert(b.toString.equals(""))
b.append("test")
assert(b.toString.equals("test"))
b.append(1)
assert(b.toString.equals("test1"))
b.append(1.0)
assert(b.toString.equals("test11.0"))
b.append(", ", 1.2, 0.10)
assert(b.toString.equals("test11.0, 1.20.1"))
}
@Test
def toStringTest2() {
val b: Builder = new Builder("init")
assert(b.toString.equals("init"))
}
}
示例10: SampleTest
//设置package包名称以及导入依赖的类
package org.schladen.nexus
import org.junit.Test
import org.schladen.nexus.models.board.{Board, Space, Team}
import org.schladen.nexus.models.game.Game
import org.schladen.nexus.models.player.Player
import play.api.libs.json.Json
class SampleTest extends UnitTest {
@Test
def testHello(): Unit = {
"hello" must include ("lo")
}
@Test
def testGame(): Unit = {
val spymaster = Player("Alex")
val guesser = Player("Jasmine")
val game = Game(spymaster, guesser)
info(game.toString)
implicit val playerFormat = Json.format[Player]
implicit val teamFormat = Json.format[Team]
implicit val spaceFormat = Json.format[Space]
implicit val boardFormat = Json.format[Board]
implicit val gameFormat = Json.format[Game]
Json.toJson(game)
}
}
示例11: StageTest
//设置package包名称以及导入依赖的类
package delorean.commands
import java.io.File
import java.nio.file.{Files, Paths}
import delorean.FileOps._
import delorean._
import org.apache.commons.io.FileUtils
import org.junit.Assert._
import org.junit.{AfterClass, BeforeClass, Test}
import scala.util.Try
class StageTest {
@Test
def stageTest(): Unit = {
val filesToStage = List("src/test/resources/")
Stage(filesToStage)
val tempFile: String = getTempPitstopFileLocation
assertTrue("_temp file should have been created in Pitstops directory", tempFile.nonEmpty)
}
}
object StageTest {
@BeforeClass
def callToRide(): Unit = {
// This will make sure it creates all the required files for the test. We are checking for CURRENT_INDICATOR
// instead of TIME_MACHINE because .tm could be created by config test
if (!Files.exists(Paths.get(CURRENT_INDICATOR))) new delorean.commands.Ride
}
@AfterClass def tearDown(): Unit = {
Try(FileUtils.deleteDirectory(new File(TIME_MACHINE)))
Try(Files.delete(Paths.get(getTempPitstopFileLocation)))
}
}
示例12: basicTriangle
//设置package包名称以及导入依赖的类
package net.ladstatt.sierpinski
import org.junit.Test
import org.junit.Assert.assertTrue
import org.junit.Assert.assertEquals
@Test def basicTriangle(): Unit = {
assertEquals(Pos(0, 0), t.a)
assertEquals(Pos(1, 0), t.b)
assertEquals(Pos(0.5f, (Math.sqrt(3) / 2).toFloat), t.c)
assertEquals(SColor.White, t.color)
}
@Test def siblingsTest(): Unit = {
assertEquals(List(
Triangle(Pos(0.25f, 0.4330127f), Pos(0.75f, 0.4330127f), Pos(0.5f, 0.8660254f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.0f, 0.0f), Pos(0.5f, 0.0f), Pos(0.25f, 0.4330127f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.5f, 0.0f), Pos(1.0f, 0.0f), Pos(0.75f, 0.4330127f), SColor(1.0, 1.0, 1.0)))
, t.siblings)
}
@Test def allSiblingsAreWhite(): Unit = assertTrue(t.siblings.forall(_.color == SColor.White))
@Test def centerTriangleIsBlack(): Unit = assertTrue(t.centerT.color == SColor.Black)
@Test def sierpinski0(): Unit = {
assertEquals(Sierpinski(List(Triangle(Pos(0.0f, 0.0f), Pos(1.0f, 0.0f), Pos(0.5f, 0.8660254f), SColor(1.0, 1.0, 1.0)))), Sierpinski(Triangle(Pos(0, 0), 1), 0))
}
@Test def sierpinski1(): Unit = {
assertEquals(
Sierpinski(List(
Triangle(Pos(0.0f, 0.0f), Pos(1.0f, 0.0f), Pos(0.5f, 0.8660254f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.5f, 0.0f), Pos(0.75f, 0.4330127f), Pos(0.25f, 0.4330127f), SColor(0.0, 0.0, 0.0)),
Triangle(Pos(0.25f, 0.4330127f), Pos(0.75f, 0.4330127f), Pos(0.5f, 0.8660254f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.0f, 0.0f), Pos(0.5f, 0.0f), Pos(0.25f, 0.4330127f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.5f, 0.0f), Pos(1.0f, 0.0f), Pos(0.75f, 0.4330127f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.25f, 0.4330127f), Pos(0.75f, 0.4330127f), Pos(0.5f, 0.8660254f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.0f, 0.0f), Pos(0.5f, 0.0f), Pos(0.25f, 0.4330127f), SColor(1.0, 1.0, 1.0)),
Triangle(Pos(0.5f, 0.0f), Pos(1.0f, 0.0f), Pos(0.75f, 0.4330127f), SColor(1.0, 1.0, 1.0)))), Sierpinski(Triangle(Pos(0, 0), 1), 1))
}
@Test def sierpinski7(): Unit = {
assertEquals(7652, Sierpinski(Triangle(Pos(0, 0), 1), 7).triangles.length)
}
}
示例13: wordCountTest
//设置package包名称以及导入依赖的类
package com.chapter16.SparkTesting
import org.scalatest.Assertions._
import org.junit.Test
import org.apache.spark.sql.SparkSession
class wordCountTest {
val spark = SparkSession
.builder
.master("local[*]")
.config("spark.sql.warehouse.dir", "E:/Exp/")
.appName(s"OneVsRestExample")
.getOrCreate()
@Test def test() {
val fileName = "C:/Users/rezkar/Downloads/words.txt"
val obj = new wordCounterTestDemo()
assert(obj.myWordCounter(fileName) == 210)
}
spark.stop()
}
示例14: ScapsServiceIntegrationTest
//设置package包名称以及导入依赖的类
package scaps.eclipse.core.services
import java.io.ByteArrayInputStream
import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.jobs.IJobChangeListener
import org.eclipse.ui.internal.WorkingSet
import org.junit.Assert._
import org.junit.Test
import org.mockito.Matchers._
import org.mockito.Mockito._
import org.scalaide.core.IScalaProject
import org.scalaide.core.testsetup.TestProjectSetup
import org.junit.Ignore
class ScapsServiceIntegrationTest extends TestProjectSetup("simple-structure-builder") {
val scapsIndexService = ScapsService.createIndexService
val scapsSearchService = ScapsService.createSearchService
@Test
@Ignore
def testIndexProject {
addSourceFile(project)("Calculator.scala", """
class Home {
def plus(num1: Int, num2: Int): Int = num1 + num2
}""")
val workingSet = new WorkingSet("testing", "testing", Array(project.javaProject))
// SUT
val job = scapsIndexService(workingSet)
job.addJobChangeListener(new IJobChangeListener {
def aboutToRun(x$1: org.eclipse.core.runtime.jobs.IJobChangeEvent): Unit = {}
def awake(x$1: org.eclipse.core.runtime.jobs.IJobChangeEvent): Unit = {}
def done(x$1: org.eclipse.core.runtime.jobs.IJobChangeEvent): Unit = {
val result = scapsSearchService("Home")
assertTrue(result.isRight)
}
def running(x$1: org.eclipse.core.runtime.jobs.IJobChangeEvent): Unit = {}
def scheduled(x$1: org.eclipse.core.runtime.jobs.IJobChangeEvent): Unit = {}
def sleeping(x$1: org.eclipse.core.runtime.jobs.IJobChangeEvent): Unit = {}
})
}
def addSourceFile(project: IScalaProject)(name: String, contents: String) = {
val folder = project.underlying.getFolder("src")
if (!folder.exists())
folder.create(IResource.NONE, true, null)
val file = folder.getFile(name)
if (!file.exists()) {
val source = new ByteArrayInputStream(contents.getBytes())
file.create(source, IResource.FORCE, null)
}
}
}
示例15: ProposicoesServiceTest
//设置package包名称以及导入依赖的类
package com.nakamura.camara.proposicoes
import com.nakamura.camara.proposicoes.proposicao.ListarProposicoesRequest
import org.apache.spark.sql.{SaveMode, SparkSession}
import org.junit.Test
import org.scalatest.Assertions
class ProposicoesServiceTest extends Assertions {
private val spark = SparkSession
.builder()
.appName("ProposicoesServiceTest")
.master("local[*]")
.getOrCreate()
private val service = new ProposicoesService(spark)
@Test
def testListarProposicoes(): Unit = {
val request = ListarProposicoesRequest(ano = 2017, sigla = "PEC")
val proposicoesTry = service.listarProposicoes(request)
assert(proposicoesTry.isSuccess)
assert(proposicoesTry.get.nonEmpty)
}
@Test
def testListarProposicoesFailure(): Unit = {
val invalidRequest = ListarProposicoesRequest()
val proposicoesTry = service.listarProposicoes(invalidRequest)
assert(proposicoesTry.isFailure)
}
@Test
def testListarSiglasProposicoes(): Unit = {
val siglasTry = service.listSiglasTipoProposioes()
assert(siglasTry.isSuccess)
assert(siglasTry.get.nonEmpty)
}
@Test
def runFetchAndStoreHistoricalData(): Unit = {
service.fetchAndStoreHistoricalData(2010 to 2017 by 1, SaveMode.Ignore)
}
}