11package com .baloise .confluence .digitalsignature ;
22
33import com .atlassian .bandana .BandanaManager ;
4+ import com .atlassian .bandana .DefaultBandanaManager ;
45import org .junit .jupiter .api .Nested ;
56import org .junit .jupiter .api .Test ;
7+ import org .mockito .ArgumentCaptor ;
68
7- import java .util .Set ;
9+ import java .util .Collections ;
810
911import static org .junit .jupiter .api .Assertions .assertEquals ;
1012import static org .junit .jupiter .api .Assertions .assertNull ;
1113import static org .mockito .Matchers .any ;
12- import static org .mockito .Mockito .mock ;
13- import static org .mockito .Mockito .when ;
14+ import static org .mockito .Mockito .*;
1415
1516class SignatureTest {
1617 @ Nested
@@ -28,8 +29,8 @@ void serialize_empty() {
2829 void serialize_initializedObject () {
2930 Signature signature = new Signature (42L , "body text" , "title text" );
3031 signature .sign ("max.mustermann" );
31- signature .setMissingSignatures (Set . of ("max.muster" ));
32- signature .setNotify (Set . of ("max.meier" ));
32+ signature .setMissingSignatures (Collections . singleton ("max.muster" ));
33+ signature .setNotify (Collections . singleton ("max.meier" ));
3334
3435 String json = signature .serialize ();
3536
@@ -46,8 +47,8 @@ void deserialize_empty() {
4647 void serializeAndDeserialize () {
4748 Signature signature = new Signature (42L , "body text" , "title text" );
4849 signature .sign ("max.mustermann" );
49- signature .setMissingSignatures (Set . of ("max.muster" ));
50- signature .setNotify (Set . of ("max.meier" ));
50+ signature .setMissingSignatures (Collections . singleton ("max.muster" ));
51+ signature .setNotify (Collections . singleton ("max.meier" ));
5152
5253 String json = signature .serialize ();
5354
@@ -60,25 +61,51 @@ void serializeAndDeserialize() {
6061
6162 @ Nested
6263 class BandanaWrapperTest {
64+ private final BandanaManager bandana = mock (DefaultBandanaManager .class );
6365 private final Signature signature = new Signature (1 , "test" , "title" );
64- private final BandanaManager bandana = mock (BandanaManager .class );
66+
67+ @ Test
68+ void toBandanaFromBandana_readAsWritten () {
69+ ArgumentCaptor <String > stringCapator = ArgumentCaptor .forClass (String .class );
70+ ArgumentCaptor <Object > objectCapator = ArgumentCaptor .forClass (Object .class );
71+
72+ String key = signature .getKey ();
73+ assertNull (Signature .fromBandana (bandana , key ), "Should not be there yet." );
74+
75+ doNothing ().when (bandana ).setValue (any (), stringCapator .capture (), objectCapator .capture ());
76+ when (bandana .getKeys (any ())).thenReturn (Collections .singletonList (key ));
77+
78+ Signature .toBandana (bandana , signature );
79+ assertEquals (key , stringCapator .getValue ());
80+ assertEquals (signature .serialize (), objectCapator .getValue ());
81+
82+ when (bandana .getValue (any (), any ())).thenCallRealMethod ();
83+ when (bandana .getValue (any (), eq (key ), eq (true ))).thenReturn (signature );
84+ assertEquals (signature , Signature .fromBandana (bandana , signature .getKey ()));
85+ }
6586
6687 @ Test
6788 void fromBandana_signature_signature () {
68- when (bandana .getValue (any (), any ())).thenReturn (signature .serialize ());
89+ String key = signature .getKey ();
90+ assertNull (Signature .fromBandana (bandana , key ), "Should not be there yet." );
6991
70- Signature readSignature = Signature .fromBandana (bandana , null );
92+ when (bandana .getKeys (any ())).thenReturn (Collections .singletonList (key ));
93+ when (bandana .getValue (any (), any ())).thenCallRealMethod ();
94+ when (bandana .getValue (any (), eq (key ), eq (true ))).thenReturn (signature );
7195
72- assertEquals (signature , readSignature );
96+ assertEquals (signature , Signature . fromBandana ( bandana , signature . getKey ()) );
7397 }
7498
7599 @ Test
76- void fromBandana_string_signatur () {
77- when (bandana .getValue (any (), any ())).thenReturn (signature );
100+ void fromBandana_string_signature () {
101+ String key = signature .getKey ();
102+ assertNull (Signature .fromBandana (bandana , key ), "Should not be there yet." );
78103
79- Signature readSignature = Signature .fromBandana (bandana , null );
104+ when (bandana .getKeys (any ())).thenReturn (Collections .singletonList (key ));
105+ when (bandana .getValue (any (), any ())).thenCallRealMethod ();
106+ when (bandana .getValue (any (), eq (key ), eq (true ))).thenReturn (signature .serialize ());
80107
81- assertEquals (signature , readSignature );
108+ assertEquals (signature , Signature . fromBandana ( bandana , signature . getKey ()) );
82109 }
83110 }
84111}
0 commit comments