Merge branch 'master' of https://github.com/eugenp/tutorials into task/BAEL-20665
# Conflicts: # core-groovy-2/src/test/groovy/com/baeldung/metaprogramming/MetaprogrammingUnitTest.groovy # core-java-modules/pom.xml # pom.xml
This commit is contained in:
@@ -2,10 +2,13 @@ package com.baeldung.metaprogramming.extension
|
||||
|
||||
import com.baeldung.metaprogramming.Employee
|
||||
|
||||
import java.time.LocalDate
|
||||
import java.time.Year
|
||||
|
||||
class BasicExtensions {
|
||||
|
||||
static int getYearOfBirth(Employee self) {
|
||||
return (new Date().getYear() + 1900) - self.age;
|
||||
return Year.now().value - self.age
|
||||
}
|
||||
|
||||
static String capitalize(String self) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.baeldung.metaprogramming
|
||||
|
||||
import groovy.time.TimeCategory
|
||||
|
||||
import java.time.LocalDate
|
||||
import java.time.Period
|
||||
import java.time.Year
|
||||
|
||||
class MetaprogrammingUnitTest extends GroovyTestCase {
|
||||
|
||||
@@ -51,15 +54,17 @@ class MetaprogrammingUnitTest extends GroovyTestCase {
|
||||
|
||||
void testJavaMetaClass() {
|
||||
String.metaClass.capitalize = { String str ->
|
||||
str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
str.substring(0, 1).toUpperCase() + str.substring(1)
|
||||
}
|
||||
assert "norman".capitalize() == "Norman"
|
||||
}
|
||||
|
||||
// void testEmployeeExtension() {
|
||||
// Employee emp = new Employee(age: 28)
|
||||
// assert emp.getYearOfBirth() == 1991
|
||||
// }
|
||||
void testEmployeeExtension() {
|
||||
def age = 28
|
||||
def expectedYearOfBirth = Year.now() - age
|
||||
Employee emp = new Employee(age: age)
|
||||
assert emp.getYearOfBirth() == expectedYearOfBirth.value
|
||||
}
|
||||
|
||||
void testJavaClassesExtensions() {
|
||||
5.printCounter()
|
||||
@@ -115,4 +120,4 @@ class MetaprogrammingUnitTest extends GroovyTestCase {
|
||||
Employee employee = new Employee(1, "Norman", "Lewis", 28)
|
||||
employee.logEmp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ class WebserviceManualTest extends GroovyTestCase {
|
||||
assert stories.size() == 5
|
||||
}
|
||||
|
||||
/* see BAEL-3753
|
||||
void test_whenConsumingSoap_thenReceiveResponse() {
|
||||
def url = "http://www.dataaccess.com/webservicesserver/numberconversion.wso"
|
||||
def soapClient = new SOAPClient(url)
|
||||
@@ -89,6 +90,7 @@ class WebserviceManualTest extends GroovyTestCase {
|
||||
def words = response.NumberToWordsResponse
|
||||
assert words == "one thousand two hundred and thirty four "
|
||||
}
|
||||
*/
|
||||
|
||||
void test_whenConsumingRestGet_thenReceiveResponse() {
|
||||
def path = "/get"
|
||||
@@ -149,4 +151,4 @@ class WebserviceManualTest extends GroovyTestCase {
|
||||
assert e?.response?.statusCode != 200
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user