package Ġname . gy ger . j money . category Ċ Ċ import Ġname . gy ger . j money . session . Session Service Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ import Ġjavax . persistence . EntityManager Ċ import Ġjavax . persistence . Persistence Context Ċ import Ġjavax . transaction . Transactional Ċ Ċ @ RunWith ( Spring Runner :: class ) Ċ @ SpringBootTest Ċ @ Transactional Ċ open Ġclass ĠCategory Service Tests Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġsession Service : ĠSession Service ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġcategory Service : ĠCategory Service ĊĊĠĠĠ Ġ@ Persistence Context ĊĠĠĠ Ġlateinit Ġprivate Ġvar Ġem : ĠEntity Manager ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsession Service . init Session () ĊĠĠĠĠĠĠĠ Ġem . flush () ĊĠĠĠĠĠĠĠ Ġem . clear () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Basics () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcategories Ġ= Ġcategory Service . getC ategories () ĊĠĠĠĠĠĠĠ Ġval Ġsize Ġ= Ġcategories . size ĊĠĠĠĠĠĠĠ ĠassertThat ( categories ). isNotEmpty () ĊĊĠĠĠĠĠĠĠ Ġval Ġnew Cat Ġ= ĠCategory () ĊĠĠĠĠĠĠĠ Ġnew Cat . name Ġ= Ġ" NEW " ĊĠĠĠĠĠĠĠ Ġnew Cat . parentId Ġ= Ġcategory Service . getRoot Category (). id ĊĠĠĠĠĠĠĠ Ġval Ġnew Cat Id Ġ= Ġcategory Service . create Category ( new Cat ) ĊĠĠĠĠĠĠĠ Ġem . flush () ĊĠĠĠĠĠĠĠ Ġem . clear () ĊĠĠĠĠĠĠĠ ĠassertThat ( category Service . getC ategories ()). has Size ( size Ġ+ Ġ 1 ) ĊĊĠĠĠĠĠĠĠ Ġcategory Service . delete Category ( new Cat Id ) ĊĠĠĠĠĠĠĠ Ġem . flush () ĊĠĠĠĠĠĠĠ Ġem . clear () ĊĠĠĠĠĠĠĠ ĠassertThat ( category Service . getC ategories ()). has Size ( size ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Split Category () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsplit Category Ġ= Ġcategory Service . get Split Category () ĊĠĠĠĠĠĠĠ ĠassertThat ( split Category . name ). isEqualTo ("[ SPLIT ]") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Transfer Category () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsplit Category Ġ= Ġcategory Service . get Transfer Category () ĊĠĠĠĠĠĠĠ ĠassertThat ( split Category . name ). isEqualTo ("[ TRANSFER ]") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Category Tree () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġcategory Tree Ġ= Ġcategory Service . get Category Tree () ĊĠĠĠĠĠĠĠ ĠassertThat ( category Tree ). isNotNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( category Tree . name ). isEqualTo ("[ ROOT ]") ĊĠĠĠĠĠĠĠ ĠassertThat ( category Tree . children ). isNotEmpty () ĊĊĠĠĠĠĠĠĠ Ġcategory Tree . name Ġ= Ġ"[ ROOT 2 ]" ĊĠĠĠĠĠĠĠ Ġcategory Service . save Category Tree ( category Tree ) ĊĠĠĠĠĠĠĠ Ġcategory Tree Ġ= Ġcategory Service . get Category Tree () ĊĠĠĠĠĠĠĠ ĠassertThat ( category Tree . name ). isEqualTo ("[ ROOT 2 ]") ĊĠĠĠ Ġ} Ċ Ċ } Ċ