Skip to content

Commit

Permalink
Replace JUnit tests by ScalaTest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Mendez committed Dec 20, 2017
1 parent 69506b7 commit ae511e1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 56 deletions.
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ lazy val commonSettings = Seq(
version := "0.3.0-SNAPSHOT",
scalaVersion := "2.12.3",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.3" % "test",
libraryDependencies += "junit" % "junit" % "4.12" % "test",
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
resolvers += Resolver.mavenLocal,
publishTo := Some(Resolver.mavenLocal)
)
Expand Down
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
4 changes: 2 additions & 2 deletions tabulas-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.version.binary}</artifactId>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package de.tudresden.inf.lat.tabulas.main
import java.io.{BufferedReader, FileReader, StringWriter}
import java.util.Objects

import org.scalatest.FunSuite

import de.tudresden.inf.lat.tabulas.datatype._
import de.tudresden.inf.lat.tabulas.parser.SimpleFormatParser
import de.tudresden.inf.lat.tabulas.renderer.SimpleFormatRenderer
import de.tudresden.inf.lat.tabulas.table.{Table, TableImpl, TableMap, TableMapImpl}
import org.junit.{Assert, Test}

/**
* This is a test of modification of a Tabula file.
*/
class MainTest {
class MainTest extends FunSuite {

val InputFileName: String = "example.properties"
val ExpectedOutputFileName: String = "example-expected.properties"
Expand Down Expand Up @@ -66,11 +67,10 @@ class MainTest {
val expectedOutput: String = readFile(fileName)

// Compare the expected output with the actual output
Assert.assertEquals(expectedOutput, writer.toString)
assert(expectedOutput === writer.toString)
}

@Test
def testAddNewField(): Unit = {
test("testAddNewField") {

// This is an example of source code where the number of authors is
// a computed value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package de.tudresden.inf.lat.tabulas.main

import java.io.{FileReader, StringWriter}

import org.scalatest.FunSuite

import de.tudresden.inf.lat.tabulas.parser.SimpleFormatParser
import de.tudresden.inf.lat.tabulas.renderer.SimpleFormatRenderer
import de.tudresden.inf.lat.tabulas.table.TableMap
import org.junit.{Assert, Test}

/**
* This is a test of normalization of files.
*/
class NormalizationTest {
class NormalizationTest extends FunSuite {

val InputFileName0: String = "example.properties"
val ExpectedOutputFileName0: String = "example-expected.properties"
Expand All @@ -33,11 +34,10 @@ class NormalizationTest {
val writer: StringWriter = new StringWriter()
val renderer: SimpleFormatRenderer = new SimpleFormatRenderer(writer)
renderer.render(tableMap)
Assert.assertEquals(expectedResult, writer.toString)
assert(expectedResult === writer.toString)
}

@Test
def testNormalization(): Unit = {
test("testNormalization") {
testNormalizationOfFile(InputFileName0, ExpectedOutputFileName0)
testNormalizationOfFile(InputFileName1, ExpectedOutputFileName1)
testNormalizationOfFile(InputFileName2, ExpectedOutputFileName2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
package de.tudresden.inf.lat.tabulas.ext.parser

import org.scalatest.FunSpec
import org.scalatest.FunSuite

/**
* Test class of MyStack[A]
*/
class MyStackTest extends FunSpec {
class MyStackTest extends FunSuite {

describe("This tests a stack") {
test("it should push and pop values in the right order") {
val calPar = new CalendarParser()
val myStack = new calPar.MyStack[String]

it("should push and pop values in the right order") {
val calPar = new CalendarParser()
val myStack = new calPar.MyStack[String]
assert(myStack.size === 0)

assert(myStack.size === 0)
myStack.push("1")
myStack.push("2")
assert(myStack.size === 2)

myStack.push("1")
myStack.push("2")
assert(myStack.size === 2)
myStack.push("2")
assert(myStack.size === 3)

myStack.push("2")
assert(myStack.size === 3)
myStack.push("3")
assert(myStack.size === 4)

myStack.push("3")
assert(myStack.size === 4)
val elem3: String = myStack.pop()
assert(elem3 === "3")
assert(myStack.size === 3)

val elem3: String = myStack.pop()
assert(elem3 === "3")
assert(myStack.size === 3)
val elem2: String = myStack.pop()
assert(elem2 === "2")
assert(myStack.size === 2)

val elem2: String = myStack.pop()
assert(elem2 === "2")
assert(myStack.size === 2)
val elem1: String = myStack.pop()
assert(elem1 === "2")
assert(myStack.size === 1)

val elem1: String = myStack.pop()
assert(elem1 === "2")
assert(myStack.size === 1)

val elem0: String = myStack.pop()
assert(elem0 === "1")
assert(myStack.size === 0)
}
val elem0: String = myStack.pop()
assert(elem0 === "1")
assert(myStack.size === 0)
}

it("should throw a NoSuchElementException after popping from an empty stack") {
val calPar = new CalendarParser()
val myStack = new calPar.MyStack[String]
intercept[NoSuchElementException] {
myStack.pop()
}
test("it should throw a NoSuchElementException after popping from an empty stack") {
val calPar = new CalendarParser()
val myStack = new calPar.MyStack[String]
intercept[NoSuchElementException] {
myStack.pop()
}

}

}

0 comments on commit ae511e1

Please sign in to comment.