Advertisement
Guest User

Untitled

a guest
Oct 30th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.17 KB | None | 0 0
  1. package com.greentea.utility.ot
  2.  
  3.  
  4. import spock.lang.Specification
  5.  
  6. class ObjectTranslatorDefaultValuesTest extends Specification {
  7.  
  8.   def 'test translate default values'() {
  9.     when:
  10.     def c = new Configuration()
  11.     def ot = new ObjectTranslator(c)
  12.     def o1 = new Bean1()
  13.  
  14.     def abstractBeanConfig = c.beanOfClass(AbstractBean.class)
  15.     def bean1Config = c.beanOfClass(Bean1.class)
  16.     def bean1DtoConfig = c.beanOfClass(Bean1DTO.class)
  17.     bean1DtoConfig.property("s1").setDefaultValue("v1")
  18.     bean1Config.property("s2").setDefaultValue("v2")
  19.     abstractBeanConfig.property("s3").setDefaultValue("v3")
  20.  
  21.     def translation = bean1Config.translationTo(Bean1DTO)
  22.     translation.srcProperty("s4").setDefaultValue("v4")
  23.     translation.destProperty("s5").setDefaultValue("v5")
  24.     def o2 = ot.translate(o1, Bean1DTO.class)
  25.     then:
  26.     o2.s1 == "v1"
  27.     o2.s2 == "v2"
  28.     o2.s3 == "v3"
  29.     o2.s4 == "v4"
  30.     o2.s5 == "v5"
  31.   }
  32.  
  33.   static abstract class AbstractBean {
  34.     String s1
  35.     String s2
  36.     String s3
  37.     String s4
  38.     String s5
  39.   }
  40.  
  41.   static class Bean1 extends AbstractBean {
  42.   }
  43.  
  44.   static class Bean1DTO extends AbstractBean {
  45.   }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement