本文整理汇总了Scala中org.junit.Before类的典型用法代码示例。如果您正苦于以下问题:Scala Before类的具体用法?Scala Before怎么用?Scala Before使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Before类的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: TestProducer
//设置package包名称以及导入依赖的类
package com.rockiey.kafka
import java.util.{Date, Properties, Random}
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import org.junit.{After, Before, Test}
class TestProducer {
val brokers = "localhost:9092"
val topic = "test"
val rnd = new Random()
val props = new Properties()
props.put("metadata.broker.list", brokers)
props.put("serializer.class", "kafka.serializer.StringEncoder")
//props.put("partitioner.class", "com.colobu.kafka.SimplePartitioner")
props.put("producer.type", "async")
//props.put("request.required.acks", "1")
var producer: Producer[String, String] = null
@Before
def before: Unit = {
val config = new ProducerConfig(props)
producer = new Producer[String, String](config)
}
@After
def after: Unit = {
producer.close()
}
def produce(events: Int): Unit = {
val t = System.currentTimeMillis()
for (nEvents <- Range(0, events)) {
val runtime = new Date().getTime()
val ip = "192.168.2." + rnd.nextInt(255)
val msg = runtime + "," + nEvents + ",www.example.com," + ip
val data = new KeyedMessage[String, String](topic, ip, msg)
producer.send(data)
}
System.out.println("sent per second: " + events * 1000 / (System.currentTimeMillis() - t))
}
@Test
def testProducer: Unit = {
produce(100)
}
@Test
def testConsumer {
}
}
示例3: DocumentTest
//设置package包名称以及导入依赖的类
package ch.epfl.callgraph.visualization
import ch.epfl.callgraph.utils.Utils.CallGraph
import ch.epfl.callgraph.visualization.view.{D3GraphView, HtmlView}
import org.junit.Assert._
import org.junit.{Before, Test}
import org.scalajs.dom.html._
import org.scalajs.{dom => sdom}
import upickle.{default => upickle}
import scala.scalajs
import scala.scalajs.js
import scala.scalajs.js.Dynamic.global
class DocumentTest {
val $ = global.jQuery
@Before
def setupDocument() : Unit = {
$("body").html("")
$("body")
.append(
global.jQuery("<div id=\"header\"><h1>Scala.js Call Graph Visualization</h1></div>" +
"<div id=\"nav\" style=\"overflow:auto\"></div>" +
"<div id=\"main\" style=\"overflow:auto\"></div>"))
HtmlView.main() // setup the file upload button
D3GraphView.setCallGraph(upickle.read[CallGraph](generateGraph))
HtmlView.updateHtmlAfterLoad(sdom.document.getElementById("nav").asInstanceOf[Div])
D3GraphView.renderGraph()
}
def generateGraph = {
"""{"classes":[{"encodedName":"s_Predef$Triple$2","displayName":"scala.Predef$Triple$2","isExported":true,"superClass":[],"interfaces":[],"methods":[]}]}"""
}
@Test def testInitialDOM(): Unit = {
assertEquals(1, $("#header").length)
assertEquals(1, $("#nav").length)
assertEquals(1, $("#main").length)
}
@Test def testInitialLayer : Unit = {
HtmlView.showLayers
assertEquals(1, $("li > a.active").length)
}
@Test def testSvgSingleNode : Unit = {
println($("svg").html())
$("svg").find("circle").each({(li: Html) => {
println($(li).attr("class"))
// $(li).contextmenu()
}}: scalajs.js.ThisFunction)
assertEquals(1, $("svg").find("circle").length)
}
}
示例4: ExampleIntegrationTest
//设置package包名称以及导入依赖的类
package scaps.eclipse
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.jdt.core.IPackageFragmentRoot
import org.eclipse.jdt.core.JavaCore
import org.eclipse.jdt.internal.core.PackageFragment
import org.junit.Before
import org.junit.Test
import org.junit.Ignore
import org.scalaide.core.testsetup.TestProjectSetup
class ExampleIntegrationTest extends TestProjectSetup("simple-structure-builder") {
@Before
def setup {
println("iuu setup test")
}
@Test
@Ignore
def test1 {
val javaProj = project.javaProject
val srcDirs = javaProj.getAllPackageFragmentRoots.filter(_.getKind == IPackageFragmentRoot.K_SOURCE).head.getChildren.last
val p: PackageFragment = srcDirs.asInstanceOf[PackageFragment]
val srcs = p.getCompilationUnits.head.getResource
println("done")
}
}
示例5: MessageTest
//设置package包名称以及导入依赖的类
package org.eck.entities
import com.google.appengine.tools.development.testing.{LocalDatastoreServiceTestConfig, LocalServiceTestHelper}
import org.junit.{Assert, After, Before, Test}
class MessageTest {
val helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(100))
@Before def setUp(): Unit = helper.setUp
@After def tearDown() = helper.tearDown()
@Test
def testSaveAndFind = {
val id = new Message("messageTitle", "messageContent").save
val message = Message.findById(id)
Assert.assertEquals(id, message.id)
Assert.assertEquals("messageTitle", message.title)
Assert.assertEquals("messageContent", message.content)
}
}
示例6: AbstractScopTest
//设置package包名称以及导入依赖的类
package polyite.schedule
import java.util.Properties
import polyite.config.Config
import org.junit.Before
import polyite.ScopInfo
import polyite.export.JSCOPInterface
import java.util.logging.Logger
import polyite.AbstractTest
import isl.Isl
object AbstractScopTest {
private def checkIsValidSched(deps : Set[Dependence], sched : isl.UnionMap) {
val schedDims : List[isl.UnionMap] = Isl.splitMultiDimUnionMap(sched)
val uncarriedDeps : Set[Dependence] = schedDims.zipWithIndex.foldLeft(deps)((remDeps : Set[Dependence], dimSched : (isl.UnionMap, Int)) => {
remDeps.view.foreach((dep : Dependence) => {
assert(!ScheduleUtils.getDirectionOfDep(dimSched._1, dep).isNegative, f"dependence ${dep} is violated by dimension ${dimSched._2}")
})
remDeps -- ScheduleUtils.getDepsCarriedBySchedule(dimSched._1, remDeps)
})
assert(uncarriedDeps.isEmpty, f"There are uncarried dependences:\n${uncarriedDeps.mkString("\n")}")
}
}
abstract class AbstractScopTest extends AbstractTest {
protected val myLogger = Logger.getLogger("")
protected var scop : ScopInfo = null
protected var deps : Set[Dependence] = null
protected var domInfo : DomainCoeffInfo = null
protected var conf : Config = null
protected var scopStr : String = null
@Before
def prepare() {
scop = JSCOPInterface.parseJSCOP(scopStr) match {
case None => throw new RuntimeException()
case Some(s) => s
}
val t : (Set[Dependence], DomainCoeffInfo) = ScheduleSpaceUtils.calcDepsAndDomInfo(scop)
deps = t._1
domInfo = t._2
conf = createTestConfig() match {
case None => throw new RuntimeException()
case Some(c) => c
}
runFurtherPreparation()
}
def runFurtherPreparation()
}
示例7: VideoTranscoderTest
//设置package包名称以及导入依赖的类
package com.waz
import java.io.File
import java.util.concurrent.CountDownLatch
import android.content.Context
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.waz.api.AssetFactory.LoadCallback
import com.waz.api.{AssetFactory, AssetForUpload}
import com.waz.bitmap.video.VideoTranscoder
import com.waz.service.ZMessaging
import com.waz.threading.Threading
import org.junit.runner.RunWith
import org.junit.{Assert, Before, Test}
import scala.concurrent.Await
import scala.concurrent.duration._
@RunWith(classOf[AndroidJUnit4])
class VideoTranscoderTest {
@Before def setUp(): Unit = {
Threading.AssertsEnabled = false
ZMessaging.onCreate(context)
}
@Test def audioTranscodingFrom8kHz(): Unit = {
val transcoder = VideoTranscoder(context)
val out = File.createTempFile("video", ".mp4", context.getCacheDir)
val future = transcoder(Uri.parse("content://com.waz.test/8khz.mp4"), out, { _ => })
Assert.assertEquals(out, Await.result(future, 15.seconds))
}
@Test def assetLoadingWithNoAudio(): Unit = {
val latch = new CountDownLatch(1)
var asset = Option.empty[AssetForUpload]
AssetFactory.videoAsset(Uri.parse("content://com.waz.test/no_audio.mp4"), new LoadCallback {
override def onLoaded(a: AssetForUpload): Unit = {
asset = Some(a)
latch.countDown()
}
override def onFailed(): Unit = {
println(s"transcode failed")
latch.countDown()
}
})
latch.await()
Assert.assertTrue(asset.isDefined)
}
def context: Context = instr.getTargetContext
def instr = InstrumentationRegistry.getInstrumentation
}
示例8: AssetMetaDataTest
//设置package包名称以及导入依赖的类
package com.waz
import android.content.Context
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.waz.model.AssetMetaData
import com.waz.service.ZMessaging
import com.waz.threading.Threading
import com.waz.utils._
import org.junit.runner.RunWith
import org.junit.{Assert, Before, Test}
import scala.concurrent.Await
import scala.concurrent.duration._
@RunWith(classOf[AndroidJUnit4])
class AssetMetaDataTest {
@Before def setUp(): Unit = {
Threading.AssertsEnabled = false
ZMessaging.onCreate(context)
}
@Test def testAudioDurationLoadingFromUri(): Unit = {
val meta = Await.result(AssetMetaData.Audio(context, Uri.parse("content://com.waz.test/32kbps.m4a")), 5.seconds)
Assert.assertEquals(309L, meta.fold2(0L, _.duration.getSeconds))
}
def context: Context = instr.getTargetContext
def instr = InstrumentationRegistry.getInstrumentation
}
示例9: ScheduleTest
//设置package包名称以及导入依赖的类
package com.gaiam.gcsis.util
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.Assert._
import org.joda.time.{Interval => JInterval}
import org.joda.time.Instant
import org.joda.time.DateTime
class ScheduleTest {
val i1 : JInterval = new JInterval(new DateTime("2010-01-01"), new DateTime("2010-02-01"))
val i2 : JInterval = new JInterval(new DateTime("2010-02-01"), new DateTime("2010-03-01"))
val i3 : JInterval = new JInterval(new DateTime("2010-03-01"), new DateTime("2010-04-01"))
val i4 : JInterval = new JInterval(new DateTime("2010-01-15"), new DateTime("2010-03-15"))
@Before
def setUp: Unit = {
}
@After
def tearDown: Unit = {
}
@Test
def testOneIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1))
val begin = new DateTime("2010-01-01")
val interval = schedule.continuousInterval(begin)
assertTrue(interval.isDefined)
assertEquals(begin, interval.get.getStart)
assertEquals(i1.getEnd, interval.get.getEnd)
}
@Test
def testTwoOverlappingIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1, i4))
val date = new DateTime("2010-01-20")
val interval = schedule.continuousInterval(date)
assertTrue(interval.isDefined)
assertTrue("interval '" + interval + "' doesn't contain date '" + date + "'", interval.get.contains(date))
assertEquals(i4.getEnd, interval.get.getEnd)
}
@Test
def testAbutsIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1, i2, i3))
val date = new DateTime("2010-01-20")
val interval = schedule.continuousInterval(date)
assertTrue(interval.isDefined)
assertTrue(interval.get.contains(date))
assertEquals(i3.getEnd, interval.get.getEnd)
}
}
示例10: LocalSparkRunner
//设置package包名称以及导入依赖的类
import com.ixeption.spark.dota2.util.Dota2Analytics
import org.apache.spark.SparkConf
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import org.junit.{Before, Test}
@Test
object LocalSparkRunner {
@Before
def prepare(): Unit = {
System.setProperty("hadoop.home.dir", "C:\\Users\\Christian\\Dev\\hadoop-2.6.0")
}
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Dota2")
conf.set("spark.master", "local[4]")
conf.set("spark.sql.warehouse.dir", "file:///C:/Users/Christian/AppData/Local/Temp/spark-warehouse")
//conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
//conf.set("spark.kryoserializer.buffer.max", "512m")
val spark: SparkSession = SparkSession.builder().appName("Dota2").config(conf).getOrCreate()
val dataFrame: DataFrame = spark.read.json("src/main/resources/data/matches.json")
//val dataFrame: DataFrame = spark.read.parquet("matchespar")
import dataFrame.sqlContext.implicits._
val items: DataFrame = spark.read.json("src/main/resources/data/items_23_06_2016.json")
.select(explode($"result.items"))
.toDF()
broadcast(items)
val heros: DataFrame = spark.read.json("src/main/resources/data/heros_01_07_2016.json")
.select(explode($"result.heroes"))
.toDF()
broadcast(heros)
val matchesDf = dataFrame.select(explode($"matches")).toDF()
Dota2Analytics.run(spark, matchesDf, heros, items)
spark.stop()
}
}
示例11: AbstractRealmTestCase
//设置package包名称以及导入依赖的类
import android.content.Context
import android.support.test.InstrumentationRegistry
import android.test.RenamingDelegatingContext
import com.github.aafa.model.User
import io.realm.RealmConfiguration.Builder
import io.realm.{Realm, RealmConfiguration}
import org.junit.Before
abstract class AbstractRealmTestCase {
var mMockContext: Context = null
lazy val realmConfiguration: RealmConfiguration = new Builder(mMockContext).deleteRealmIfMigrationNeeded().build()
lazy val realm: Realm = Realm.getInstance(realmConfiguration)
@Before
def setup() = {
mMockContext = new RenamingDelegatingContext(InstrumentationRegistry.getInstrumentation.getTargetContext, "test_")
clearData
}
def clearData: Unit = {
realmTransaction(_.clear(classOf[User]))
}
def realmTransaction(action: Realm => Unit) = {
realm.beginTransaction()
action(realm)
realm.commitTransaction()
}
}
示例12: MowerFactoryImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.model.factory
import com.xebia.mowitnow.model.Entity.{Orientation, Mower, Position}
import com.xebia.mowitnow.model.Factory.MowerFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class MowerFactoryImplTest extends Assertions {
var mowerFactory: MowerFactoryImpl = null
@Before def initialize() {
mowerFactory = new MowerFactoryImpl
}
@Test def testCreateMower() {
// Create mower with position 1,5 & orientation N
assertEquals(Some(Mower(Position(1,5, Orientation.N))), mowerFactory.createMower("1 5 N"))
//Try to create mower with unsupported orientation
assertEquals(None, mowerFactory.createMower("1 5 A"))
}
}
示例13: GroundFactoryImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.model.factory
import com.xebia.mowitnow.model.Entity.{Dimension, Ground}
import com.xebia.mowitnow.model.Factory.GroundFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class GroundFactoryImplTest extends Assertions {
var groundFactory: GroundFactoryImpl = null
@Before def initialize() {
groundFactory = new GroundFactoryImpl
}
@Test def testCreateGround() {
assertEquals(Some(Ground(Dimension(5, 5))), groundFactory.createGround("5 5"))
assertEquals(Some(Ground(Dimension(5, 5))), groundFactory.createGround(" 5 5 "))
// Handling of unsupported format of ground
assertEquals(None, groundFactory.createGround("A 5"))
assertEquals(None, groundFactory.createGround(""))
assertEquals(None, groundFactory.createGround("5.5 5"))
assertEquals(None, groundFactory.createGround("-1 5"))
}
}
示例14: InstructionFactoryImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.model.factory
import com.xebia.mowitnow.model.Entity.{Instruction, Dimension, Ground}
import com.xebia.mowitnow.model.Factory.InstructionFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class InstructionFactoryImplTest extends Assertions {
var instructionFactory: InstructionFactoryImpl = null
@Before def initialize() {
instructionFactory = new InstructionFactoryImpl
}
@Test def testCreateInstruction() {
// Create a list of instruction with some unsupported instructions
assertEquals(Some(List(Instruction.A, Instruction.A, Instruction.G, Instruction.A, Instruction.A, Instruction.D, Instruction.G, Instruction.A, Instruction.A)), instructionFactory.createInstruction("AAGEAADGAA"))
// Create list of instruction from only unsupported instructions
assertEquals(None, instructionFactory.createInstruction("IEH"))
}
}
示例15: GroundServiceImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.service
import com.xebia.mowitnow.model.Entity.{Orientation, Position, Dimension, Ground}
import com.xebia.mowitnow.model.Factory.GroundFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class GroundServiceImplTest extends Assertions {
implicit var groundFactory: GroundFactoryImpl = null
var groundService: GroundServiceImpl = null
@Before def initialize() {
groundFactory = new GroundFactoryImpl
groundService = new GroundServiceImpl
}
@Test def testIsInsideGround() {
val ground = Ground(Dimension(5,5))
assertEquals(true, groundService.isInsideGround(ground,Position(1,5,Orientation.N)))
assertEquals(false, groundService.isInsideGround(ground,Position(-1,5,Orientation.N)))
assertEquals(false, groundService.isInsideGround(ground,Position(5,6,Orientation.N)))
assertEquals(false, groundService.isInsideGround(ground,Position(6,5,Orientation.N)))
}
}