diff --git a/core-scala/src/main/scala/com/baeldung/scala/Employee.scala b/core-scala/src/main/scala/com/baeldung/scala/Employee.scala index 397f166aa7..9291d958b3 100644 --- a/core-scala/src/main/scala/com/baeldung/scala/Employee.scala +++ b/core-scala/src/main/scala/com/baeldung/scala/Employee.scala @@ -22,6 +22,6 @@ class Employee(val name : String, * A Trait which will make the toString return upper case value. */ trait UpperCasePrinter { - override def toString = super.toString toUpperCase + override def toString: String = super.toString toUpperCase } diff --git a/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala b/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala index df97013206..02c41a5f8c 100644 --- a/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala +++ b/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala @@ -11,7 +11,7 @@ object HigherOrderFunctions { def mapReduce(r : (Int, Int) => Int, i : Int, m : Int => Int, - a : Int, b : Int) = { + a : Int, b : Int): Int = { def iter(a : Int, result : Int) : Int = { if (a > b) result else iter(a + 1, r(m(a), result)) diff --git a/core-scala/src/main/scala/com/baeldung/scala/Utils.scala b/core-scala/src/main/scala/com/baeldung/scala/Utils.scala index 93cd3e697e..20bc413646 100644 --- a/core-scala/src/main/scala/com/baeldung/scala/Utils.scala +++ b/core-scala/src/main/scala/com/baeldung/scala/Utils.scala @@ -7,9 +7,9 @@ package com.baeldung.scala * */ object Utils { - def average(x : Double, y : Double) = (x + y) / 2 + def average(x : Double, y : Double): Double = (x + y) / 2 - def randomLessThan(d : Double) = { + def randomLessThan(d : Double): Double = { var random = 0d do { random = Math.random() diff --git a/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala index 71422a8b4f..584038ee2c 100644 --- a/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala +++ b/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala @@ -1,32 +1,32 @@ package com.baeldung.scala import com.baeldung.scala.ControlStructuresDemo._ -import org.junit.Test import org.junit.Assert.assertEquals +import org.junit.Test class ControlStructuresDemoUnitTest { @Test - def givenTwoIntegers_whenGcdCalled_thenCorrectValueReturned = { + def givenTwoIntegers_whenGcdCalled_thenCorrectValueReturned() = { assertEquals(3, gcd(15, 27)) } @Test - def givenTwoIntegers_whenGcdIterCalled_thenCorrectValueReturned = { + def givenTwoIntegers_whenGcdIterCalled_thenCorrectValueReturned() = { assertEquals(3, gcdIter(15, 27)) } @Test - def givenTwoIntegers_whenRangeSumcalled_thenCorrectValueReturned = { + def givenTwoIntegers_whenRangeSumcalled_thenCorrectValueReturned() = { assertEquals(55, rangeSum(1, 10)) } @Test - def givenPositiveInteger_whenFactorialInvoked_thenCorrectValueReturned = { + def givenPositiveInteger_whenFactorialInvoked_thenCorrectValueReturned() = { assertEquals(720, factorial(6)) } @Test - def whenFactorialOf0Invoked_then1Returned = { + def whenFactorialOf0Invoked_then1Returned() = { assertEquals(1, factorial(0)) } diff --git a/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala index c51631dd2c..0828752a8a 100644 --- a/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala +++ b/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala @@ -6,20 +6,20 @@ import org.junit.Test class EmployeeUnitTest { @Test - def whenEmployeeSalaryIncremented_thenCorrectSalary = { + def whenEmployeeSalaryIncremented_thenCorrectSalary() = { val employee = new Employee("John Doe", 1000) employee.incrementSalary() assertEquals(1020, employee.salary) } @Test - def givenEmployee_whenToStringCalled_thenCorrectStringReturned = { + def givenEmployee_whenToStringCalled_thenCorrectStringReturned() = { val employee = new Employee("John Doe", 1000) assertEquals("Employee(name=John Doe, salary=1000)", employee.toString) } @Test - def givenEmployeeWithTrait_whenToStringCalled_thenCorrectStringReturned = { + def givenEmployeeWithTrait_whenToStringCalled_thenCorrectStringReturned() = { val employee = new Employee("John Doe", 1000) with UpperCasePrinter assertEquals("EMPLOYEE(NAME=JOHN DOE, SALARY=1000)", employee.toString) diff --git a/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala index 63530ecaf4..240c879d7f 100644 --- a/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala +++ b/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala @@ -1,14 +1,13 @@ package com.baeldung.scala +import com.baeldung.scala.HigherOrderFunctions.mapReduce import org.junit.Assert.assertEquals import org.junit.Test -import HigherOrderFunctions.mapReduce - class HigherOrderFunctionsUnitTest { @Test - def whenCalledWithSumAndSquareFunctions_thenCorrectValueReturned = { + def whenCalledWithSumAndSquareFunctions_thenCorrectValueReturned() = { def square(x : Int) = x * x def sum(x : Int, y : Int) = x + y @@ -20,7 +19,7 @@ class HigherOrderFunctionsUnitTest { } @Test - def whenComputingSumOfSquaresWithAnonymousFunctions_thenCorrectValueReturned = { + def whenComputingSumOfSquaresWithAnonymousFunctions_thenCorrectValueReturned() = { def sumSquares(a : Int, b : Int) = mapReduce((x, y) => x + y, 0, x => x * x, a, b) @@ -28,7 +27,7 @@ class HigherOrderFunctionsUnitTest { } @Test - def givenCurriedFunctions_whenInvoked_thenCorrectValueReturned = { + def givenCurriedFunctions_whenInvoked_thenCorrectValueReturned() = { // a curried function def sum(f : Int => Int)(a : Int, b : Int) : Int = diff --git a/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala index 5cc19e9215..ac27389d70 100644 --- a/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala +++ b/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala @@ -1,14 +1,12 @@ package com.baeldung.scala -import scala.Range - import org.junit.Assert.assertFalse import org.junit.Test class IntSetUnitTest { @Test - def givenSetof1To10_whenContains11Called_thenFalse = { + def givenSetof1To10_whenContains11Called_thenFalse() = { // Set up a set containing integers 1 to 10. val set1To10 = diff --git a/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala index 47f9873aad..e4995201d8 100644 --- a/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala +++ b/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala @@ -1,34 +1,29 @@ package com.baeldung.scala -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue +import com.baeldung.scala.Utils.{average, fibonacci, power, randomLessThan} +import org.junit.Assert.{assertEquals, assertTrue} import org.junit.Test -import Utils.average -import Utils.fibonacci -import Utils.power -import Utils.randomLessThan - class UtilsUnitTest { @Test - def whenAverageCalled_thenCorrectValueReturned() = { + def whenAverageCalled_thenCorrectValueReturned(): Unit = { assertEquals(15.0, average(10, 20), 1e-5) } @Test - def whenRandomLessThanInvokedWithANumber_thenARandomLessThanItReturned = { + def whenRandomLessThanInvokedWithANumber_thenARandomLessThanItReturned: Unit = { val d = 0.1 assertTrue(randomLessThan(d) < d) } @Test - def whenPowerInvokedWith2And3_then8Returned = { + def whenPowerInvokedWith2And3_then8Returned: Unit = { assertEquals(8, power(2, 3)) } @Test - def whenFibonacciCalled_thenCorrectValueReturned = { + def whenFibonacciCalled_thenCorrectValueReturned: Unit = { assertEquals(1, fibonacci(0)) assertEquals(1, fibonacci(1)) assertEquals(fibonacci(6),