BAEL-2726_Introduction_to_Traits_in_Groovy (#6384)
This commit is contained in:
parent
156441843c
commit
2f9bc1b54a
@ -0,0 +1,3 @@
|
||||
package com.baeldung
|
||||
|
||||
class Car implements VehicleTrait {}
|
@ -22,7 +22,7 @@ trait UserTrait implements Human {
|
||||
msg
|
||||
}
|
||||
|
||||
def whoAmI() {
|
||||
def self() {
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.baeldung
|
||||
|
||||
trait VehicleTrait extends WheelTrait {
|
||||
|
||||
String showWheels() {
|
||||
return "Num of Wheels $noOfWheels"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.baeldung
|
||||
|
||||
trait WheelTrait {
|
||||
|
||||
int noOfWheels
|
||||
|
||||
}
|
@ -57,7 +57,7 @@ class TraitsUnitTest extends Specification {
|
||||
|
||||
def 'Should return employee instance when using Employee.whoAmI method' () {
|
||||
when:
|
||||
def emp = employee.whoAmI()
|
||||
def emp = employee.self()
|
||||
then:
|
||||
emp
|
||||
emp instanceof Employee
|
||||
|
Loading…
x
Reference in New Issue
Block a user