/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 8 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . android . tools . property . panel . impl . model Ċ Ċ import Ġcom . android . Sdk Constants . ANDROID _ URI Ċ import Ġcom . android . Sdk Constants . ATTR _ ID Ċ import Ġcom . android . Sdk Constants . ATTR _ TEXT Ċ import Ġcom . android . tools . adt ui . model . std ui . ValueChanged Listener Ċ import Ġcom . android . tools . property . panel . api . Property Item Ċ import Ġcom . android . tools . property . panel . impl . model . util . Fake Inspector Line Model Ċ import Ġcom . android . tools . property . panel . impl . model . util . Fake Line Type Ċ import Ġcom . android . tools . property . panel . impl . model . util . Fake Async Property Item Ċ import Ġcom . android . tools . property . panel . impl . model . util . Fake Property Item Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mockito . mock Ċ import Ġorg . mockito . Mockito . never Ċ import Ġorg . mockito . Mockito . verify Ċ import Ġorg . mockito . Mockito . verify Zero Interactions Ċ Ċ class ĠTextField Property Editor Model Test Ġ{ ĊĊĠ Ġprivate Ġfun Ġcreate Model (): ĠPair < TextField Property Editor Model , ĠValue Changed Listener > Ġ{ ĊĠĠĠ Ġval Ġproperty Ġ= ĠFake Property Item ( ANDROID _ URI , Ġ" text ", Ġ" hello ") ĊĠĠĠ Ġproperty . defaultValue Ġ= Ġ" from " ĊĠĠĠ Ġreturn Ġcreate Model ( property ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate Model ( property : ĠProperty Item ): ĠPair < TextField Property Editor Model , ĠValue Changed Listener > Ġ{ ĊĠĠĠ Ġval Ġmodel Ġ= ĠTextField Property Editor Model ( property , Ġtrue ) ĊĠĠĠ Ġval Ġlistener Ġ= Ġmock ( ValueChanged Listener :: class . java ) ĊĠĠĠ Ġmodel . addListener ( listener ) ĊĠĠĠ Ġreturn ĠPair ( model , Ġlistener ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Value () Ġ{ ĊĠĠĠ Ġval Ġ( model , Ġ_) Ġ= Ġcreate Model () ĊĠĠĠ ĠassertThat ( model . value ). isEqualTo (" hello ") ĊĠĠĠ ĠassertThat ( model . place Holder Value ). isEqualTo (" from ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Enter () Ġ{ ĊĠĠĠ Ġval Ġ( model , Ġ_) Ġ= Ġcreate Model () ĊĠĠĠ Ġval Ġline Ġ= ĠFake Inspector Line Model ( Fake Line Type . PROPERTY ) ĊĠĠĠ Ġmodel . line Model Ġ= Ġline ĊĠĠĠ Ġmodel . text Ġ= Ġ" world " ĊĠĠĠ Ġmodel . commit () ĊĠĠĠ ĠassertThat ( model . property . value ). isEqualTo (" world ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Escape () Ġ{ ĊĠĠĠ Ġval Ġ( model , Ġlistener ) Ġ= Ġcreate Model () ĊĠĠĠ Ġmodel . escape () ĊĠĠĠ ĠassertThat ( model . property . value ). isEqualTo (" hello ") ĊĠĠĠ Ġverify ( listener ). value Changed () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Focus Gain Will Read Value From Model () Ġ{ ĊĠĠĠ Ġ// Ġsetup ĊĠĠĠ Ġval Ġ( model , Ġlistener ) Ġ= Ġcreate Model () ĊĠĠĠ Ġmodel . text Ġ= Ġ"# 3 3 3 3 3 3 " ĊĠĠĠ Ġmodel . focus G ained () ĊĊĠĠĠ ĠassertThat ( model . text ). isEqualTo (" hello ") ĊĠĠĠ Ġverify Zero Interactions ( listener ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Focus Loss Will Update Value () Ġ{ ĊĠĠĠ Ġ// Ġsetup ĊĠĠĠ Ġval Ġ( model , Ġ_) Ġ= Ġcreate Model () ĊĠĠĠ Ġmodel . focus G ained () ĊĠĠĠ Ġmodel . text Ġ= Ġ"# 3 3 3 3 3 3 " ĊĊĠĠĠ Ġ// Ġtest ĊĠĠĠ Ġmodel . focus Lost () ĊĠĠĠ ĠassertThat ( model . has Focus ). isFalse () ĊĠĠĠ ĠassertThat ( model . property . value ). isEqualTo ("# 3 3 3 3 3 3 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Focus Loss With Un changed Value Will Not Update Value () Ġ{ ĊĠĠĠ Ġ// Ġsetup ĊĠĠĠ Ġval Ġ( model , Ġlistener ) Ġ= Ġcreate Model () ĊĠĠĠ Ġmodel . focus G ained () ĊĊĠĠĠ Ġ// Ġtest ĊĠĠĠ Ġmodel . focus Lost () ĊĠĠĠ ĠassertThat ( model . property . value ). isEqualTo (" hello ") ĊĠĠĠ Ġverify ( listener , Ġnever ()). value Changed () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Enter Key With Async Property Setter DoesNot Navigate To Next Editor () Ġ{ ĊĠĠĠ Ġ// Ġsetup ĊĠĠĠ Ġval Ġproperty Ġ= ĠFake Async Property Item ( ANDROID _ URI , ĠATTR _ ID , Ġ" textView ") ĊĠĠĠ Ġval Ġ( model , Ġ_) Ġ= Ġcreate Model ( property ) ĊĠĠĠ Ġval Ġline Ġ= ĠFake Inspector Line Model ( Fake Line Type . PROPERTY ) ĊĠĠĠ Ġmodel . line Model Ġ= Ġline ĊĠĠĠ Ġmodel . focus G ained () ĊĠĠĠ Ġmodel . text Ġ= Ġ" imageView " ĊĊĠĠĠ Ġ// Ġtest ĊĠĠĠ Ġmodel . commit () ĊĠĠĠ ĠassertThat ( property . last Updated Value ). isEqualTo (" imageView ") ĊĠĠĠ ĠassertThat ( property . update Count ). isEqualTo ( 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Focus Loss After Enter Key With Async Property Setter () Ġ{ ĊĠĠĠ Ġ// Ġsetup ĊĠĠĠ Ġval Ġproperty Ġ= ĠFake Property Item ( ANDROID _ URI , ĠATTR _ ID , Ġ" textView ") ĊĠĠĠ Ġval Ġ( model , Ġ_) Ġ= Ġcreate Model ( property ) ĊĠĠĠ Ġmodel . focus G ained () ĊĠĠĠ Ġmodel . text Ġ= Ġ" imageView " ĊĠĠĠ Ġmodel . commit () ĊĊĠĠĠ Ġ// Ġtest ĊĠĠĠ Ġmodel . focus Lost () ĊĠĠĠ ĠassertThat ( property . value ). isEqualTo (" imageView ") ĊĠĠĠ ĠassertThat ( property . update Count ). isEqualTo ( 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Update After Property Change () Ġ{ ĊĠĠĠ Ġ// Ġsetup ĊĠĠĠ Ġval Ġproperty Ġ= ĠFake Property Item ( ANDROID _ URI , ĠATTR _ TEXT , Ġ" Hello ") ĊĠĠĠ Ġval Ġ( model , Ġlistener ) Ġ= Ġcreate Model ( property ) ĊĊĠĠĠ Ġ// Ġtest ĊĠĠĠ Ġproperty . value Ġ= Ġ" World " ĊĠĠĠ Ġmodel . refresh () ĊĠĠĠ ĠassertThat ( model . text ). isEqualTo (" World ") ĊĠĠĠ Ġverify ( listener ). value Changed () ĊĠ Ġ} Ċ } Ċ