Skip to content

Commit fefd64f

Browse files
author
Matteo Di Pirro
committed
Merge branch 'upstream-master' into scala-463
# Conflicts: # build.sbt
2 parents e1a1859 + 2e67b5e commit fefd64f

File tree

18 files changed

+196
-2
lines changed

18 files changed

+196
-2
lines changed

build.sbt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,24 @@ lazy val scala_libraries_3 = (project in file("scala-libraries-3"))
284284
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.8.1"
285285
)
286286

287+
lazy val scala_libraries_os = (project in file("scala-libraries-os"))
288+
.settings(
289+
name := "scala-libraries",
290+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.2" % Test,
291+
libraryDependencies ++= Seq(
292+
"org.apache.logging.log4j" %% "log4j-api-scala" % "12.0",
293+
"org.apache.logging.log4j" % "log4j-core" % "2.13.0" % Runtime
294+
),
295+
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.8.1"
296+
)
297+
298+
lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
299+
.settings(
300+
name := "scala-libraries-4",
301+
libraryDependencies += "com.lihaoyi" %% "utest" % "0.8.1" % "test",
302+
testFrameworks += new TestFramework("utest.runner.Framework")
303+
)
304+
287305
lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
288306
.settings(
289307
name := "scala-libraries",

scala-core-collection-2/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- [Get a List Item by Index in Scala](https://www.baeldung.com/scala/list-get-item-by-index)
55
- [Guide to Scala ListSet](https://www.baeldung.com/scala/listset)
66
- [Guide to Scala ListMap](https://www.baeldung.com/scala/listmap)
7+
- [How to Flatten Collections in Scala](https://www.baeldung.com/scala/flattening-collections)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.scala.mergemaps
2+
3+
object CombineIterables {
4+
5+
def combineIterables[K, V](
6+
a: Map[K, Iterable[V]],
7+
b: Map[K, Iterable[V]]
8+
): Map[K, Iterable[V]] = {
9+
a ++ b.map { case (k, v) => k -> (v ++ a.getOrElse(k, Iterable.empty)) }
10+
}
11+
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baedung.scala.mergemaps
2+
3+
import com.baeldung.scala.mergemaps.CombineIterables
4+
import org.scalatest.{FlatSpec, Matchers}
5+
6+
class MergeMapsUnitTest extends FlatSpec with Matchers {
7+
8+
"++ operator" should "merge maps preferring duplicates from second map" in {
9+
val firstMap = Map(1 -> "Apple", 5 -> "Banana", 3 -> "Orange");
10+
val secondMap = Map(5 -> "Pear", 4 -> "Cherry");
11+
12+
firstMap ++ secondMap should equal(
13+
Map(1 -> "Apple", 5 -> "Pear", 3 -> "Orange", 4 -> "Cherry")
14+
)
15+
}
16+
17+
"combineIterables" should "combine values for duplicate keys" in {
18+
val firstMap = Map(1 -> List(1, 2, 3))
19+
val secondMap = Map(1 -> List(4, 5))
20+
21+
CombineIterables.combineIterables(firstMap, secondMap) should equal(
22+
Map(1 -> List(4, 5, 1, 2, 3))
23+
)
24+
}
25+
}

scala-libraries-3/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
- [A Guide to the Scala Retry Library](https://www.baeldung.com/scala/retry-library)
1010
- [Introduction to Lightbend Config](https://www.baeldung.com/scala/lightbend-config)
1111
- [Introduction to Apache Log4j in Scala](https://www.baeldung.com/scala/apache-log4j)
12-
- [Introduction to Tapir](https://www.baeldung.com/scala/tapir)
13-
- [How to Execute OS Commands in Scala Using os-lib](https://www.baeldung.com/scala/os-lib)
12+
- [Introduction to Tapir](https://www.baeldung.com/scala/tapir)

scala-libraries-4/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Relevant Articles
2+
- [Introduction to uTest](https://www.baeldung.com/scala/utest-intro)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.scala.utest
2+
3+
import utest._
4+
5+
import scala.concurrent.Future
6+
import scala.concurrent.ExecutionContext.Implicits.global
7+
8+
object AsyncTest extends TestSuite {
9+
def getFromDB(): Future[Int] = Future { 42 }
10+
11+
override def tests: Tests = Tests {
12+
test("get something from database") {
13+
getFromDB().map(v => assert(v == 42))
14+
}
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.scala.utest
2+
3+
import utest._
4+
5+
object BeforeAfterTest extends TestSuite {
6+
println("This is executed before the tests")
7+
override def utestAfterAll() = {
8+
println("This method will be executed after all the tests")
9+
}
10+
override def tests: Tests = Tests {
11+
test("simple test") {
12+
assert(1 == 1)
13+
}
14+
test("simple test 2") {
15+
assert(2 == 2)
16+
}
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.scala.utest
2+
3+
import utest._
4+
5+
object ExceptionHandling extends TestSuite {
6+
override def tests: Tests = Tests {
7+
def funnyMethod: String = throw new RuntimeException("Uh oh...")
8+
test("Handle an exception") {
9+
val ex = intercept[RuntimeException] {
10+
funnyMethod
11+
}
12+
assert(ex.getMessage == "Uh oh...")
13+
}
14+
}
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.scala.utest
2+
3+
import utest._
4+
5+
object NestedTest extends TestSuite {
6+
override def tests: Tests = Tests {
7+
test("outer test") - {
8+
val list = List(1, 2)
9+
println("This is an outer level of the test.")
10+
test("inner test 1") - {
11+
val list2 = List(10, 20)
12+
list.zip(list2) ==> List((1, 10), (2, 20))
13+
}
14+
test("inner test 2") - {
15+
val str = List("a", "b")
16+
list.zip(str) ==> List((1, "a"), (2, "b"))
17+
}
18+
}
19+
test("outer test 2") - {
20+
println("there is no nesting level here")
21+
assert(true)
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)