package Ġde . m cell a . spring . learn tool . learn Ċ Ċ import Ġde . m cell a . spring . learn tool . UnitTest Ċ import Ġde . m cell a . spring . learn tool . card . Card Ċ import Ġde . m cell a . spring . learn tool . card . Card Id Ċ import Ġde . m cell a . spring . learn tool . card . Card Service Ċ import Ġde . m cell a . spring . learn tool . card . exceptions . Card NotFoundException Ċ import Ġde . m cell a . spring . learn tool . learn . exceptions . Card Binding Exception Ċ import Ġde . m cell a . spring . learn tool . learn . exceptions . Learn Card AlreadyExists Exception Ċ import Ġde . m cell a . spring . learn tool . learn . exceptions . Learn Card NotFoundException Ċ import Ġde . m cell a . spring . learn tool . learn . exceptions . Learn Cards NotFoundException Ċ import Ġde . m cell a . spring . learn tool . learn . storage . Learn Card Entity Ċ import Ġde . m cell a . spring . learn tool . learn . storage . Learn Card Repository Ċ import Ġde . m cell a . spring . learn tool . workspace . Workspace Ċ import Ġjava . time . Instant Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . Zone Offset Ċ import Ġjava . util . Optional Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertTrue Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . experimental . categories . Category Ċ import Ġorg . mockito . Argument Captor Ċ import Ġorg . mockito . Argument Matchers . any Ċ import Ġorg . mockito . Mockito Ċ Ċ @ Category ( UnitTest :: class ) Ċ class ĠLearn Service Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġcard Service Ġ= ĠMockito . mock ( Card Service :: class . java ) ĊĊĠĠĠ Ġprivate Ġval Ġlearn Card Repository Ġ= ĠMockito . mock ( Learn Card Repository :: class . java ) ĊĊĠĠĠ Ġprivate Ġval Ġlearn Service Ġ= ĠLearn Service ( card Service , Ġlearn Card Repository ) ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠLearn Card AlreadyExists Exception :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġcreating Ġa ĠLearn Card Ġand Ġthe ĠLearn Card Ġalready Ġexists , Ġthen Ġthrow ĠLearn Card AlreadyExists Exception `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . create ( workspace , Ġcard Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġcreating Ġa ĠLearn Card Ġand Ġthe ĠCard Ġdoes Ġnot Ġexist , Ġthen Ġthrow ĠCard NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). then Throw ( Card NotFoundException ( card Id )) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . create ( workspace , Ġcard Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard Binding Exception :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġcreating Ġa ĠLearn Card Ġand Ġthe ĠCard Ġbelongs Ġto Ġa Ġdifferent ĠWorkspace , Ġthen Ġthrow ĠCard Binding Exception `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġ" another Workspace Test ", Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entity Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card Entity ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . create ( workspace , Ġcard Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġcreating Ġa ĠLearn Card , Ġthen Ġcall Ġthe Ġmethod Ġsave Ġof ĠLearn Card Repository `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entity Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card Entity ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . create ( workspace , Ġcard Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġargument Captor Ġ= ĠArgument Captor . for Class ( Learn Card Entity :: class . java ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). save ( argument Captor . capture ()) ĊĠĠĠĠĠĠĠ Ġval Ġcreated Learn Card Entity Ġ= Ġargument Captor . value ĊĠĠĠĠĠĠĠ ĠassertEquals ( Learn Card Entity . create Initial ( card Id , Ġworkspace , Ġcreated Learn Card Entity . last Review ), Ġcreated Learn Card Entity ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġcreating Ġa ĠLearn Card , Ġthen Ġreturn Ġthe ĠLearn Card `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entity Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card Entity ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= Ġlearn Service . create ( workspace , Ġcard Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Learn Card Ġ= ĠLearn Card ( card Id . id , Ġworkspace . name , Ġlearn Card Entity . last Review , Ġlearn Card Entity . next Review , Ġlearn Card Entity . re pet itions , Ġlearn Card Entity . ease Factor , Ġlearn Card Entity . interval Days ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Learn Card , Ġlearn Card ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠLearn Card AlreadyExists Exception :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠLearn Card , Ġwhen Ġcreating Ġa ĠLearn Card Ġand Ġthe ĠLearn Card Ġalready Ġexists , Ġthen Ġthrow ĠLearn Card AlreadyExists Exception `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġval Ġtoday Ġ= ĠInstant . now () ĊĠĠĠĠĠĠĠ Ġval Ġend Ġ= ĠLocalDate . now (). plus Days ( 1 L ). at Start OfDay (). to Instant ( Zone Offset . UTC ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card ( card Id . id , Ġ" workspace Test ", Ġtoday , Ġend , Ġ 0 , Ġ 1 . 3 f , Ġ 0 ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . create ( learn Card ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠLearn Card , Ġwhen Ġcreating Ġa ĠLearn Card , Ġthen Ġcall Ġthe Ġmethod Ġsave Ġof ĠLearn Card Repository Ġand Ġreturn Ġthe ĠLearn Card `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . exists ById ( card Id . id )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġtoday Ġ= ĠInstant . now () ĊĠĠĠĠĠĠĠ Ġval Ġend Ġ= ĠLocalDate . now (). plus Days ( 1 L ). at Start OfDay (). to Instant ( Zone Offset . UTC ) ĊĠĠĠĠĠĠĠ Ġval Ġoriginal Learn Card Ġ= ĠLearn Card ( card Id . id , Ġworkspace . name , Ġtoday , Ġend , Ġ 0 , Ġ 1 . 3 f , Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entity Ġ= ĠLearn Card Entity ( card Id . id , Ġworkspace . name , Ġtoday , Ġend , Ġ 0 , Ġ 1 . 3 f , Ġ 0 ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card Entity ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= Ġlearn Service . create ( original Learn Card ) ĊĊĠĠĠĠĠĠĠ Ġval Ġargument Captor Ġ= ĠArgument Captor . for Class ( Learn Card Entity :: class . java ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). save ( argument Captor . capture ()) ĊĠĠĠĠĠĠĠ Ġval Ġcreated Learn Card Entity Ġ= Ġargument Captor . value ĊĠĠĠĠĠĠĠ ĠassertEquals ( Learn Card Entity ( card Id . id , Ġworkspace . name , Ġtoday , Ġend , Ġ 0 , Ġ 1 . 3 f , Ġ 0 ), Ġcreated Learn Card Entity ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( original Learn Card , Ġlearn Card ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġretrieving Ġa ĠCard Ġfrom Ġthe ĠWorkspace , Ġthen Ġcall Ġthe Ġmethod Ġfind First By Workspace Name And Next Review Before OrderBy Next Review Ġof ĠLearn Card Repository `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġexpected Card Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entity Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ Ġval Ġtoday Ġ= ĠLocalDate . now () ĊĠĠĠĠĠĠĠ Ġval Ġend Ġ= Ġtoday . plus Days ( 1 L ). at Start OfDay (). to Instant ( Zone Offset . UTC ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findFirst By Workspace Name And Next Review Before OrderBy Next Review ( workspace . name , Ġend )). thenReturn ( Optional . of ( learn Card Entity )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( expected Card ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . get Card ( workspace ) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). findFirst By Workspace Name And Next Review Before OrderBy Next Review ( workspace . name , Ġend ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġretrieving Ġa ĠCard Ġfrom Ġthe ĠWorkspace , Ġthen Ġcall Ġthe Ġmethod Ġfind ById Ġof ĠCard Service Ġand Ġreturn Ġthe ĠCard `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġexpected Card Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ Ġval Ġtoday Ġ= ĠLocalDate . now () ĊĠĠĠĠĠĠĠ Ġval Ġend Ġ= Ġtoday . plus Days ( 1 L ). at Start OfDay (). to Instant ( Zone Offset . UTC ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findFirst By Workspace Name And Next Review Before OrderBy Next Review ( workspace . name , Ġend )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( expected Card ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= Ġlearn Service . get Card ( workspace ) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( card Service ). findById ( card Id ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Card , Ġcard ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠLearn Cards NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġretrieving Ġa ĠCard Ġfrom Ġthe ĠWorkspace Ġand Ġno ĠLearn Cards Ġfor Ġthe Ġgiven ĠWorkspace Ġname Ġexist , Ġthen Ġthrow ĠLearn Cards NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġtoday Ġ= ĠLocalDate . now () ĊĠĠĠĠĠĠĠ Ġval Ġend Ġ= Ġtoday . plus Days ( 1 L ). at Start OfDay (). to Instant ( Zone Offset . UTC ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findFirst By Workspace Name And Next Review Before OrderBy Next Review ( workspace . name , Ġend )). thenReturn ( Optional . empty ()) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . get Card ( workspace ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġretrieving Ġa ĠCard Ġfrom Ġthe ĠWorkspace Ġand Ġthe ĠCard Ġdoes Ġnot Ġexist Ġinto Ġthe ĠWorkspace , Ġthen Ġthrow ĠCard NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ Ġval Ġtoday Ġ= ĠLocalDate . now () ĊĠĠĠĠĠĠĠ Ġval Ġend Ġ= Ġtoday . plus Days ( 1 L ). at Start OfDay (). to Instant ( Zone Offset . UTC ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findFirst By Workspace Name And Next Review Before OrderBy Next Review ( workspace . name , Ġend )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). then Throw ( Card NotFoundException ( card Id )) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . get Card ( workspace ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġthe Ġevaluation Ġparameters , Ġwhen Ġevaluating Ġa ĠCard , Ġthen Ġcall Ġthe Ġmethod Ġfind ById Ġof ĠCard Service `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġevaluation Parameters Ġ= ĠEvaluation Parameters ( 5 ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . evaluate Card ( workspace , Ġcard Id , Ġevaluation Parameters ) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( card Service ). findById ( card Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġthe Ġevaluation Ġparameters , Ġwhen Ġevaluating Ġa ĠCard , Ġthen Ġcall Ġthe Ġmethod Ġfind ById Ġof ĠLearn Card Repository `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġevaluation Parameters Ġ= ĠEvaluation Parameters ( 5 ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . evaluate Card ( workspace , Ġcard Id , Ġevaluation Parameters ) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). findById ( card Id . id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġthe Ġevaluation Ġparameters , Ġwhen Ġevaluating Ġa ĠCard , Ġthen Ġcall Ġthe Ġmethod Ġsave Ġof ĠLearn Card Repository `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġevaluation Parameters Ġ= ĠEvaluation Parameters ( 5 ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . evaluate Card ( workspace , Ġcard Id , Ġevaluation Parameters ) ĊĊĠĠĠĠĠĠĠ Ġval Ġargument Captor Ġ= ĠArgument Captor . for Class ( Learn Card Entity :: class . java ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). save ( argument Captor . capture ()) ĊĠĠĠĠĠĠĠ Ġval Ġupdated Learn Card Entity Ġ= Ġargument Captor . value ĊĠĠĠĠĠĠĠ ĠassertEquals ( card Id , ĠCard Id ( updated Learn Card Entity . id )) ĊĠĠĠĠĠĠĠ ĠassertTrue Ġ{ Ġupdated Learn Card Entity . next Review Ġ> Ġlearn Card . next Review Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġthe Ġevaluation Ġparameters , Ġwhen Ġevaluating Ġa ĠCard Ġand Ġthe ĠCard Ġdoes Ġnot Ġexist , Ġthen Ġthrow ĠCard NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġevaluation Parameters Ġ= ĠEvaluation Parameters ( 5 ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). then Throw ( Card NotFoundException ( card Id )) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . evaluate Card ( workspace , Ġcard Id , Ġevaluation Parameters ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard Binding Exception :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġthe Ġevaluation Ġparameters , Ġwhen Ġevaluating Ġa ĠCard Ġand Ġthe ĠCard Ġdoes Ġnot Ġexist Ġinto Ġthe ĠWorkspace , Ġthen Ġthrow ĠCard Binding Exception `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġevaluation Parameters Ġ= ĠEvaluation Parameters ( 5 ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġ" another Workspace Name ", Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . save ( any ( Learn Card Entity :: class . java ))). thenReturn ( learn Card ) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . evaluate Card ( workspace , Ġcard Id , Ġevaluation Parameters ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠLearn Card NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġthe Ġevaluation Ġparameters , Ġwhen Ġevaluating Ġa ĠCard Ġand Ġthe ĠLearn Card Ġdoes Ġnot Ġexist , Ġthen Ġthrow ĠLearn Card NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġevaluation Parameters Ġ= ĠEvaluation Parameters ( 5 ) ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . empty ()) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . evaluate Card ( workspace , Ġcard Id , Ġevaluation Parameters ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname , Ġwhen Ġretrieving Ġthe ĠLearn Cards , Ġthen Ġcall Ġthe Ġmethod ĠfindBy Workspace Name Ġof ĠLearn Card Repository `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entity Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Entities Ġ= ĠlistOf ( learn Card Entity ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findBy Workspace Name ( workspace . name )). thenReturn ( learn Card Entities ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlearn Cards Ġ= Ġlearn Service . get Learn Card sBy Workspace ( workspace ) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). findBy Workspace Name ( workspace . name ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Learn Card Ġ= ĠLearn Card ( learn Card Entity . id , Ġlearn Card Entity . workspace Name , Ġlearn Card Entity . last Review , Ġlearn Card Entity . next Review , Ġlearn Card Entity . re pet itions , Ġlearn Card Entity . ease Factor , Ġlearn Card Entity . interval Days ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Learn Cards Ġ= ĠlistOf ( expected Learn Card ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Learn Cards , Ġlearn Cards ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġdeleting Ġa ĠLearn Card Ġand Ġthe ĠCard Ġdoes Ġnot Ġexist , Ġthen Ġthrow ĠCard NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). then Throw ( Card NotFoundException ( card Id )) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . delete ( workspace , Ġcard Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠCard Binding Exception :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġdeleting Ġa ĠLearn Card Ġand Ġthe ĠCard Ġbelongs Ġto Ġa Ġdifferent ĠWorkspace , Ġthen Ġthrow ĠCard Binding Exception `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġ" another Workspace Test ", Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . delete ( workspace , Ġcard Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠLearn Card NotFoundException :: class ) ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġdeleting Ġa ĠLearn Card Ġand Ġthe ĠLearn Card Ġdoes Ġnot Ġexist , Ġthen Ġthrow ĠLearn Card NotFoundException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . empty ()) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . delete ( workspace , Ġcard Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Ġa ĠWorkspace Ġname Ġand Ġa ĠCard Ġid , Ġwhen Ġdeleting Ġa ĠLearn Card , Ġthen Ġcall Ġthe Ġmethod Ġdelete Ġof ĠLearn Card Repository `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġworkspace Ġ= ĠWorkspace (" workspace Test ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Id Ġ= ĠCard Id (" 9 e 4 9 3 dc 0 - ef 7 5 - 4 0 3 f - b 5 d 6 - ed 5 1 0 6 3 4 f 8 a 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠCard ( card Id . id , Ġworkspace . name , Ġ" question ", Ġ" response ") ĊĠĠĠĠĠĠĠ ĠMockito .` when `( card Service . findById ( card Id )). thenReturn ( card ) ĊĠĠĠĠĠĠĠ Ġval Ġlearn Card Ġ= ĠLearn Card Entity . create Initial ( card Id , Ġworkspace , ĠInstant . now ()) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( learn Card Repository . findById ( card Id . id )). thenReturn ( Optional . of ( learn Card )) ĊĊĠĠĠĠĠĠĠ Ġlearn Service . delete ( workspace , Ġcard Id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġargument Captor Ġ= ĠArgument Captor . for Class ( Learn Card Entity :: class . java ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( learn Card Repository ). delete ( argument Captor . capture ()) ĊĠĠĠĠĠĠĠ Ġval Ġdeleted Learn Card Ġ= Ġargument Captor . value ĊĠĠĠĠĠĠĠ ĠassertEquals ( learn Card , Ġdeleted Learn Card ) ĊĠĠĠ Ġ} Ċ } Ċ