本文整理汇总了Scala中org.junit.Assert类的典型用法代码示例。如果您正苦于以下问题:Scala Assert类的具体用法?Scala Assert怎么用?Scala Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assert类的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: 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")
}
}
示例3: 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)
}
}
示例4: HttpRddIOTest
//设置package包名称以及导入依赖的类
import java.util.Date
import org.apache.spark.SparkConf
import org.apache.spark.serializer.KryoSerializer
import org.apache.spark.sql.execution.streaming.BufferedTextCollector
import org.apache.spark.sql.execution.streaming.HttpTextReceiver
import org.apache.spark.sql.execution.streaming.HttpTextSender
import org.apache.spark.sql.execution.streaming.TextConsolePrinter
import org.junit.Test
import org.junit.Assert
class HttpRddIOTest {
val LINES1 = Array[(String, Int, Boolean, Char, Float, Double, Long, Date)](("hello1", 1, true, 'a', 0.1f, 0.1d, 1L, new Date(10000)),
("hello2", 2, false, 'b', 0.2f, 0.2d, 2L, new Date(20000)), ("hello3", 3, true, 'c', 0.3f, 0.3d, 3L, new Date(30000)));
@Test
def testHttpRddIO() {
//starts a http server with a receiver servlet
val receiver = HttpTextReceiver.startReceiver(new SparkConf(), "receiver1", "/xxxx", 8080);
receiver.addListener(new TextConsolePrinter());
val buffer = new BufferedTextCollector();
receiver.addListener(buffer);
val sender = new HttpTextSender("http://localhost:8080/xxxx");
val kryoSerializer = new KryoSerializer(new SparkConf());
sender.sendObjectArray(kryoSerializer, "topic-1", 1, LINES1);
receiver.stop();
val data = buffer.dump().map(_._1).toArray;
Assert.assertArrayEquals(LINES1.asInstanceOf[Array[Object]], data.asInstanceOf[Array[Object]]);
}
}
示例5: RFParameterBuilderTest
//设置package包名称以及导入依赖的类
package reforest.rf.parameter
import org.junit.{Assert, Test}
class RFParameterBuilderTest {
@Test
def builderInit = {
val b1 = RFParameterBuilder.apply
val b2 = RFParameterBuilder.apply
val parameter1 = b1.build
val parameter2 = b2.build
Assert.assertNotEquals(parameter1.UUID, parameter2.UUID)
}
@Test
def builderInitFromParameter = {
val b1 = RFParameterBuilder.apply
val parameter1 = b1.build
val b2 = RFParameterBuilder.apply(parameter1)
val parameter2 = b2.build
Assert.assertEquals(parameter1.UUID, parameter2.UUID)
}
@Test
def builderAddParameter = {
val b1 = RFParameterBuilder.apply
.addParameter(RFParameterType.Instrumented, true)
.addParameter(RFParameterType.SparkCompressionCodec, "snappy")
.addParameter(RFParameterType.MaxNodesConcurrent, 5)
.addParameter(RFParameterType.PoissonMean, 5.3)
val parameter1 = b1.build
Assert.assertEquals(true, parameter1.Instrumented)
Assert.assertEquals("snappy", parameter1.sparkCompressionCodec)
Assert.assertEquals(5, parameter1.maxNodesConcurrent)
Assert.assertEquals(5.3, parameter1.poissonMean, 0.000001)
}
}
示例6: RFParameterTest
//设置package包名称以及导入依赖的类
package reforest.rf.parameter
import org.junit.{Assert, Test}
class RFParameterTest {
@Test
def builderInit = {
val b1 = RFParameterBuilder.apply
.addParameter(RFParameterType.NumTrees, 100)
val parameter1 = b1.build
Assert.assertEquals(1, parameter1.numTrees.length)
Assert.assertEquals(100, parameter1.getMaxNumTrees)
val parameter2 = parameter1.applyNumTrees(101)
Assert.assertEquals(1, parameter1.numTrees.length)
Assert.assertEquals(1, parameter2.numTrees.length)
Assert.assertEquals(100, parameter1.getMaxNumTrees)
Assert.assertEquals(101, parameter2.getMaxNumTrees)
}
}
示例7: 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)
}
}
示例8: BytecodeBackendUtilTest
//设置package包名称以及导入依赖的类
package com.github.kaeluka.cflat.test
import com.github.kaeluka.cflat.ast._
import com.github.kaeluka.cflat.backend.BytecodeBackendUtil
import org.hamcrest.MatcherAssert._
import org.hamcrest.Matchers._
import org.junit.{Assert, Test}
class BytecodeBackendUtilTest {
def foo_or_bar = Alt(("foo", None), ("bar", None))
def foo_or_bar_or_baz = Alt(("foo", None), ("bar", None), ("baz", None))
def ten_times_eps = Rep("col", 10, None, "ok", None)
def assertSize(term : TypeSpec, n : Option[Int]) = {
Assert.assertEquals(s"type spec $term must have size $n", n, term.getSize)
}
@Test
def testPairingFunction() {
def testPairingFunction(f: (Long, Long) => Long, frev: Long => (Long, Long)) = {
for (i <- 0L to 100L; j <- 0L to 100L) {
assertThat(frev(f(i, j)), equalTo((i, j)))
}
}
testPairingFunction(BytecodeBackendUtil.cantorPairingFunction, BytecodeBackendUtil.cantorPairingFunctionRev)
}
}
示例9: 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
}
示例10: 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
}
示例11: KafkaStatsdReporterConfigTest
//设置package包名称以及导入依赖的类
package org.kongo.kafka.metrics
import org.junit.Assert
import org.junit.Test
import org.kongo.kafka.metrics.config.KafkaStatsdReporterConfig
class KafkaStatsdReporterConfigTest {
@Test
def defaultMapConfig(): Unit = {
val config = TestUtils.emptyMapConfig
testDefaults(config)
}
@Test
def defaultVerifiableProperties(): Unit = {
val config = TestUtils.emptyVerfiableConfig
testDefaults(config)
}
private def testDefaults(config: KafkaStatsdReporterConfig): Unit = {
Assert.assertEquals("localhost", config.host)
Assert.assertEquals(8125, config.port)
Assert.assertEquals(10, config.pollingIntervalSecs)
Assert.assertEquals(None, config.include)
Assert.assertEquals(None, config.exclude)
Assert.assertEquals(Dimension.Values, config.dimensions)
Assert.assertEquals(false, config.enabled)
Assert.assertEquals("kafka", config.prefix)
}
}
示例12: KafkaMetricsRegistryTest
//设置package包名称以及导入依赖的类
package org.kongo.kafka.metrics
import org.junit.Assert
import org.junit.Test
class KafkaMetricsRegistryTest {
@Test
def updateMetrics(): Unit = {
val registry = KafkaMetricsRegistry()
Assert.assertEquals(0, registry.metrics.size)
registry.update(TestUtils.dummyKafkaMetric)
Assert.assertEquals(1, registry.metrics.size)
}
@Test
def removeMetrics(): Unit = {
val metric = TestUtils.dummyKafkaMetric
val registry = KafkaMetricsRegistry()
registry.update(metric)
Assert.assertEquals(1, registry.metrics.size)
registry.remove(metric)
Assert.assertEquals(0, registry.metrics.size)
}
}
示例13: RegexMetricPredicateTest
//设置package包名称以及导入依赖的类
package org.kongo.kafka.metrics
import java.util.regex.Pattern
import org.junit.Assert
import org.junit.Test
class RegexMetricPredicateTest {
private val startsWithFoo = Pattern.compile("foo.*")
private val containsBar = Pattern.compile(".*bar.*")
@Test
def allMatchingPredicate(): Unit = {
val all = RegexMetricPredicate(None, None)
Assert.assertTrue(all.matches(""))
Assert.assertTrue(all.matches("some"))
Assert.assertTrue(all.matches("foo.bar.test"))
}
@Test
def includePatternPredicate(): Unit = {
val startsWith = RegexMetricPredicate(Some(startsWithFoo), None)
Assert.assertTrue(startsWith.matches("foo"))
Assert.assertTrue(startsWith.matches("foo.bar.test"))
Assert.assertFalse(startsWith.matches(""))
Assert.assertFalse(startsWith.matches("bar"))
Assert.assertFalse(startsWith.matches("bar.foo"))
Assert.assertFalse(startsWith.matches("bar.foo.test"))
}
@Test
def excludePatternPredicate(): Unit = {
val doesNotStartsWith = RegexMetricPredicate(None, Some(startsWithFoo))
Assert.assertFalse(doesNotStartsWith.matches("foo"))
Assert.assertFalse(doesNotStartsWith.matches("foo.bar.test"))
Assert.assertTrue(doesNotStartsWith.matches(""))
Assert.assertTrue(doesNotStartsWith.matches("bar"))
Assert.assertTrue(doesNotStartsWith.matches("bar.foo"))
Assert.assertTrue(doesNotStartsWith.matches("bar.foo.test"))
}
@Test
def includeExcludePatternsPredicate(): Unit = {
val matcher = RegexMetricPredicate(Some(startsWithFoo), Some(containsBar))
Assert.assertTrue(matcher.matches("foo"))
Assert.assertFalse(matcher.matches("foo.bar.test"))
Assert.assertFalse(matcher.matches(""))
Assert.assertFalse(matcher.matches("bar"))
Assert.assertFalse(matcher.matches("bar.foo"))
Assert.assertFalse(matcher.matches("bar.foo.test"))
}
}
示例14: SimpleValidationTest
//设置package包名称以及导入依赖的类
package com.github.rehei.scala.forms.test
import com.github.rehei.scala.forms.test.model.Company
import org.junit.Test
import com.github.rehei.scala.forms.test.model.Employee
import com.github.rehei.scala.forms.validation.Validator
import com.github.rehei.scala.macros.Reflection
import com.github.rehei.scala.forms.util.Conversions._
import com.github.rehei.scala.forms.rules.IsTrue
import com.github.rehei.scala.forms.rules.MinLength
import com.github.rehei.scala.forms.rules.MaxLength
import org.junit.Assert
import org.junit.Assert._
class SimpleValidationTest {
@Test
def test() {
val company = new Reflection[Company]
val employee = new Reflection[Employee]
val model = new Company()
model.employees.add(new Employee())
model.employees.add(new Employee())
model.name = "123"
val validator = {
Validator
.attach(
company(_.name)
.assert(MinLength(5).message("Too short"))
.assert(MaxLength(10).message("Too long")))
}
val results = validator.validate(model)
val v0 = results(0)
val v1 = results(1)
assertEquals(v0.isValid, false)
assertEquals(v0.ruleName, classOf[MinLength].getCanonicalName)
assertEquals(v1.isValid, true)
assertEquals(v1.ruleName, classOf[MaxLength].getCanonicalName)
println(v0)
println(v1)
}
}
示例15: DerivedAttributesShouldBeReadOnlyTest
//设置package包名称以及导入依赖的类
package com.github.bmaggi.sysml.evaluation
/**
* Created by Benoit Maggi on 11/05/2016.
*/
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.{Assert, Test}
import scala.xml.{Node, XML}
@RunWith(classOf[JUnit4])
class DerivedAttributesShouldBeReadOnlyTest {
@Test def test() {
val xml = XML.load(getClass.getResource("/SysML.xmi"))
val ownedAttributeList = (xml \\ XMIUtils.ownedAttribute).filter(x => // filter the sequence of ownedAttribute
((x \\ "isDerived").nonEmpty && (x \\ "isReadOnly").isEmpty))
Assert.assertTrue("Some elements are missing read only:\n" + prettyPrint(ownedAttributeList), ownedAttributeList.isEmpty)
}
//TODO : there is probably a better Scala way to do that
def prettyPrint(ownedAttributeSeq: Seq[Node]): String = {
var res = new String()
for (missingReadOnly: Node <- ownedAttributeSeq) {
res ++= missingReadOnly.attribute(XMIUtils.XMI_XMNLS, "id").get.toString
res ++= "\n"
}
return res
}
}