BAEL-3734: Fix testEmployeeExtension unit test
This commit is contained in:
parent
0846a55404
commit
66af11b926
@ -2,10 +2,13 @@ package com.baeldung.metaprogramming.extension
|
|||||||
|
|
||||||
import com.baeldung.metaprogramming.Employee
|
import com.baeldung.metaprogramming.Employee
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.Year
|
||||||
|
|
||||||
class BasicExtensions {
|
class BasicExtensions {
|
||||||
|
|
||||||
static int getYearOfBirth(Employee self) {
|
static int getYearOfBirth(Employee self) {
|
||||||
return (new Date().getYear() + 1900) - self.age;
|
return LocalDate.now().getYear() - self.age;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String capitalize(String self) {
|
static String capitalize(String self) {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.baeldung.metaprogramming
|
package com.baeldung.metaprogramming
|
||||||
|
|
||||||
import groovy.time.TimeCategory
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.Period
|
||||||
|
import java.time.Year
|
||||||
|
|
||||||
class MetaprogrammingUnitTest extends GroovyTestCase {
|
class MetaprogrammingUnitTest extends GroovyTestCase {
|
||||||
|
|
||||||
@ -57,8 +60,10 @@ class MetaprogrammingUnitTest extends GroovyTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void testEmployeeExtension() {
|
void testEmployeeExtension() {
|
||||||
Employee emp = new Employee(age: 28)
|
def age = 28
|
||||||
assert emp.getYearOfBirth() == 1992
|
def expectedYearOfBirth = Year.now() - age
|
||||||
|
Employee emp = new Employee(age: age)
|
||||||
|
assert emp.getYearOfBirth() == expectedYearOfBirth.value
|
||||||
}
|
}
|
||||||
|
|
||||||
void testJavaClassesExtensions() {
|
void testJavaClassesExtensions() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user