/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 0 Ġ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 . idea . adb . wire less Ċ Ċ import Ġcom . android . tools . idea . ui . One Time Override Focus Traversal Policy Ċ import Ġcom . google . common . truth . Truth Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġjava . awt . Component Ċ import Ġjava . awt . Container Ċ import Ġjava . awt . Focus Traversal Policy Ċ Ċ class ĠOne Time Override Focus Traversal Policy Test Ġ{ ĊĠ Ġprivate Ġval Ġmock Policy Ġ= ĠMockito . mock ( Focus Traversal Policy :: class . java ) ĊĠ Ġprivate Ġval Ġcontainer Ġ= Ġ ĠMockito . mock ( Container :: class . java ) ĊĠ Ġprivate Ġval Ġcomponent 1 Ġ= Ġ ĠMockito . mock ( Component :: class . java ) ĊĠ Ġprivate Ġval Ġcomponent 2 Ġ= Ġ ĠMockito . mock ( Component :: class . java ) ĊĠ Ġprivate Ġval Ġcomponent 3 Ġ= Ġ ĠMockito . mock ( Component :: class . java ) ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġ// ĠSetup Ġa Ġfocus Ġcycle Ġfrom Ġ[ component 1 , Ġcomponent 2 , Ġcomponent 3 , Ġcomponent 1 , Ġ...] ĊĠĠĠ Ġ` when `( mock Policy . getComponent After ( container , Ġcomponent 1 )). thenReturn ( component 2 ) ĊĠĠĠ Ġ` when `( mock Policy . getComponent After ( container , Ġcomponent 2 )). thenReturn ( component 3 ) ĊĠĠĠ Ġ` when `( mock Policy . getComponent After ( container , Ġcomponent 3 )). thenReturn ( component 1 ) ĊĊĠĠĠ Ġ` when `( mock Policy . getComponent Before ( container , Ġcomponent 1 )). thenReturn ( component 3 ) ĊĠĠĠ Ġ` when `( mock Policy . getComponent Before ( container , Ġcomponent 2 )). thenReturn ( component 1 ) ĊĠĠĠ Ġ` when `( mock Policy . getComponent Before ( container , Ġcomponent 3 )). thenReturn ( component 2 ) ĊĊĠĠĠ Ġ` when `( mock Policy . getFirst Component ( container )). thenReturn ( component 1 ) ĊĊĠĠĠ Ġ` when `( mock Policy . getLast Component ( container )). thenReturn ( component 3 ) ĊĊĠĠĠ Ġ` when `( mock Policy . getDefault Component ( container )). thenReturn ( component 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġdefault Should Not Override Anything () Ġ{ ĊĠĠĠ Ġ// ĠPrepare ĊĠĠĠ Ġval Ġpolicy Ġ= ĠOne Time Override Focus Traversal Policy ( mock Policy ) ĊĊĠĠĠ Ġ// ĠAct ĊĠĠĠ Ġval Ġafter Ġ= Ġpolicy . getComponent After ( container , Ġcomponent 1 ) ĊĠĠĠ Ġval Ġbefore Ġ= Ġpolicy . getComponent Before ( container , Ġcomponent 1 ) ĊĠĠĠ Ġval Ġfirst Ġ= Ġpolicy . getFirst Component ( container ) ĊĠĠĠ Ġval Ġlast Ġ= Ġpolicy . getLast Component ( container ) ĊĠĠĠ Ġval Ġdefault Ġ= Ġpolicy . getDefault Component ( container ) ĊĊĠĠĠ Ġ// ĠAssert ĊĠĠĠ ĠTr uth . assertThat ( after ). isEqualTo ( component 2 ) ĊĠĠĠ ĠTr uth . assertThat ( before ). isEqualTo ( component 3 ) ĊĠĠĠ ĠTr uth . assertThat ( first ). isEqualTo ( component 1 ) ĊĠĠĠ ĠTr uth . assertThat ( last ). isEqualTo ( component 3 ) ĊĠĠĠ ĠTr uth . assertThat ( default ). isEqualTo ( component 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġoverride Component After Should Work () Ġ{ ĊĠĠĠ Ġ// ĠPrepare ĊĠĠĠ Ġval Ġpolicy Ġ= ĠOne Time Override Focus Traversal Policy ( mock Policy ) ĊĠĠĠ Ġpolicy . one Time Component After . set ( component 3 ) ĊĊĠĠĠ Ġ// ĠAct ĊĠĠĠ Ġval Ġafter 1 Ġ= Ġpolicy . getComponent After ( container , Ġcomponent 1 ) ĊĠĠĠ Ġval Ġafter 2 Ġ= Ġpolicy . getComponent After ( container , Ġcomponent 1 ) ĊĊĠĠĠ Ġ// ĠAssert ĊĠĠĠ ĠTr uth . assertThat ( after 1 ). isEqualTo ( component 3 ) ĊĠĠĠ ĠTr uth . assertThat ( after 2 ). isEqualTo ( component 2 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġoverride Component Before Should Work () Ġ{ ĊĠĠĠ Ġ// ĠPrepare ĊĠĠĠ Ġval Ġpolicy Ġ= ĠOne Time Override Focus Traversal Policy ( mock Policy ) ĊĠĠĠ Ġpolicy . one Time Component Before . set ( component 3 ) ĊĊĠĠĠ Ġ// ĠAct ĊĠĠĠ Ġval Ġbefore 1 Ġ= Ġpolicy . getComponent Before ( container , Ġcomponent 2 ) ĊĠĠĠ Ġval Ġbefore 2 Ġ= Ġpolicy . getComponent Before ( container , Ġcomponent 2 ) ĊĊĠĠĠ Ġ// ĠAssert ĊĠĠĠ ĠTr uth . assertThat ( before 1 ). isEqualTo ( component 3 ) ĊĠĠĠ ĠTr uth . assertThat ( before 2 ). isEqualTo ( component 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġoverride First Component Should Work () Ġ{ ĊĠĠĠ Ġ// ĠPrepare ĊĠĠĠ Ġval Ġpolicy Ġ= ĠOne Time Override Focus Traversal Policy ( mock Policy ) ĊĠĠĠ Ġpolicy . one Time First Component . set ( component 3 ) ĊĊĠĠĠ Ġ// ĠAct ĊĠĠĠ Ġval Ġfirst 1 Ġ= Ġpolicy . getFirst Component ( container ) ĊĠĠĠ Ġval Ġfirst 2 Ġ= Ġpolicy . getFirst Component ( container ) ĊĊĠĠĠ Ġ// ĠAssert ĊĠĠĠ ĠTr uth . assertThat ( first 1 ). isEqualTo ( component 3 ) ĊĠĠĠ ĠTr uth . assertThat ( first 2 ). isEqualTo ( component 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġoverride Last Component Should Work () Ġ{ ĊĠĠĠ Ġ// ĠPrepare ĊĠĠĠ Ġval Ġpolicy Ġ= ĠOne Time Override Focus Traversal Policy ( mock Policy ) ĊĠĠĠ Ġpolicy . one Time Last Component . set ( component 1 ) ĊĊĠĠĠ Ġ// ĠAct ĊĠĠĠ Ġval Ġlast 1 Ġ= Ġpolicy . getLast Component ( container ) ĊĠĠĠ Ġval Ġlast 2 Ġ= Ġpolicy . getLast Component ( container ) ĊĊĠĠĠ Ġ// ĠAssert ĊĠĠĠ ĠTr uth . assertThat ( last 1 ). isEqualTo ( component 1 ) ĊĠĠĠ ĠTr uth . assertThat ( last 2 ). isEqualTo ( component 3 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġoverride Default Component Should Work () Ġ{ ĊĠĠĠ Ġ// ĠPrepare ĊĠĠĠ Ġval Ġpolicy Ġ= ĠOne Time Override Focus Traversal Policy ( mock Policy ) ĊĠĠĠ Ġpolicy . one Time Default Component . set ( component 3 ) ĊĊĠĠĠ Ġ// ĠAct ĊĠĠĠ Ġval Ġdefault 1 Ġ= Ġpolicy . getDefault Component ( container ) ĊĠĠĠ Ġval Ġdefault 2 Ġ= Ġpolicy . getDefault Component ( container ) ĊĊĠĠĠ Ġ// ĠAssert ĊĠĠĠ ĠTr uth . assertThat ( default 1 ). isEqualTo ( component 3 ) ĊĠĠĠ ĠTr uth . assertThat ( default 2 ). isEqualTo ( component 1 ) ĊĠ Ġ} Ċ } Ċ