// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . configuration Store . xml Ċ Ċ import Ġcom . intellij . configuration Store . Data Writer Ċ import Ġcom . intellij . configuration Store . State Map Ċ import Ġcom . intellij . configuration Store . XmlElement Storage Ċ import Ġcom . intellij . configuration Store . to Buffer Ex posing ByteArray Ċ import Ġcom . intellij . openapi . util . J DOM Util Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . j dom . Element Ċ import Ġorg . junit . Test Ċ Ċ class ĠXml Element Storage Test Ġ{ ĊĠ Ġ@ Test Ġfun ĠtestGet State Succeeded () Ġ{ ĊĠĠĠ Ġval Ġstorage Ġ= ĠMy XmlElement Storage ( Element (" root "). add Content ( Element (" component "). setAttribute (" name ", Ġ" test "). add Content ( Element (" foo ")) )) ĊĠĠĠ Ġval Ġstate Ġ= Ġstorage . getState ( this , Ġ" test ", ĠElement :: class . java ) ĊĠĠĠ ĠassertThat ( state ). isNotNull ĊĠĠĠ ĠassertThat ( state !!. name ). isEqualTo (" component ") ĊĠĠĠ ĠassertThat ( state . getChild (" foo ")). isNotNull ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` get Ġstate Ġnot Ġsucceeded `() Ġ{ ĊĠĠĠ Ġval Ġstorage Ġ= ĠMy XmlElement Storage ( Element (" root ")) ĊĠĠĠ Ġval Ġstate Ġ= Ġstorage . getState ( this , Ġ" test ", ĠElement :: class . java ) ĊĠĠĠ ĠassertThat ( state ). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` set Ġstate Ġoverrides Ġold Ġstate `() Ġ{ ĊĠĠĠ Ġval Ġstorage Ġ= ĠMy XmlElement Storage ( Element (" root "). add Content ( Element (" component "). setAttribute (" name ", Ġ" test "). add Content ( Element (" foo ")) )) ĊĠĠĠ Ġval ĠnewState Ġ= ĠElement (" component "). setAttribute (" name ", Ġ" test "). add Content ( Element (" bar ")) ĊĠĠĠ Ġval Ġexternal ization Session Ġ= Ġstorage . create Save Session Producer () !! ĊĠĠĠ Ġexternal ization Session . setState ( null , Ġ" test ", ĠnewState ) ĊĠĠĠ Ġexternal ization Session . create Save Session () !!. save () ĊĠĠĠ ĠassertThat ( storage . saved Element ). isNotNull ĊĠĠĠ ĠassertThat ( storage . saved Element !!. getChild (" component "). getChild (" bar ")). isNotNull ĊĠĠĠ ĠassertThat ( storage . saved Element !!. getChild (" component "). getChild (" foo ")). isNull () ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠMy XmlElement Storage ( private Ġval Ġelement : ĠElement ) Ġ: ĠXml Element Storage ("", Ġ" root ") Ġ{ ĊĠĠĠ Ġoverride Ġval Ġis Use V fs For Write : ĠBoolean ĊĠĠĠĠĠ Ġget () Ġ= Ġfalse ĊĊĠĠĠ Ġvar Ġsaved Element : ĠElement ? Ġ= Ġnull ĊĊĠĠĠ Ġoverride Ġfun Ġload Local Data () Ġ= Ġelement ĊĊĠĠĠ Ġoverride Ġfun Ġcreate Save Session ( states : ĠState Map ) Ġ= Ġobject Ġ: ĠXml Element Storage Save Session < My XmlElement Storage >( states , Ġthis ) Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġsave Loc ally ( data Writer : ĠData Writer ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( data Writer Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġsaved Element Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġsaved Element Ġ= ĠJ DOM Util . load ( data Writer . to Buffer Ex posing ByteArray (). toByteArray (). inputStream ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ