1+ package org .cryptomator .domain ;
2+
3+ import org .junit .jupiter .api .BeforeEach ;
4+ import org .junit .jupiter .api .DisplayName ;
5+ import org .junit .jupiter .api .Nested ;
6+ import org .junit .jupiter .api .Test ;
7+
8+ import static org .hamcrest .CoreMatchers .is ;
9+ import static org .hamcrest .MatcherAssert .assertThat ;
10+ import static org .junit .jupiter .api .Assertions .assertFalse ;
11+ import static org .junit .jupiter .api .Assertions .assertTrue ;
12+ import static org .mockito .Mockito .mock ;
13+ import static org .mockito .Mockito .when ;
14+
15+ public class VaultTest {
16+
17+ private Cloud cloud ;
18+
19+ @ BeforeEach
20+ public void setup () {
21+ cloud = mock (Cloud .class );
22+ when (cloud .type ()).thenReturn (CloudType .WEBDAV );
23+ }
24+
25+ private Vault .Builder minimalVaultBuilder () {
26+ return Vault .aVault ()
27+ .withId (1L )
28+ .withName ("TestVault" )
29+ .withPath ("/vaults/test" )
30+ .withCloud (cloud )
31+ .withPosition (0 );
32+ }
33+
34+ @ Nested
35+ @ DisplayName ("hubVault field" )
36+ class HubVaultField {
37+
38+ @ Test
39+ @ DisplayName ("Default hubVault is false when not set" )
40+ public void defaultHubVaultIsFalse () {
41+ Vault vault = minimalVaultBuilder ().build ();
42+
43+ assertFalse (vault .isHubVault ());
44+ }
45+
46+ @ Test
47+ @ DisplayName ("withHubVault(true) sets isHubVault() to true" )
48+ public void withHubVaultTrueSetsHubVaultTrue () {
49+ Vault vault = minimalVaultBuilder ()
50+ .withHubVault (true )
51+ .build ();
52+
53+ assertTrue (vault .isHubVault ());
54+ }
55+
56+ @ Test
57+ @ DisplayName ("withHubVault(false) sets isHubVault() to false" )
58+ public void withHubVaultFalseSetsHubVaultFalse () {
59+ Vault vault = minimalVaultBuilder ()
60+ .withHubVault (false )
61+ .build ();
62+
63+ assertFalse (vault .isHubVault ());
64+ }
65+
66+ @ Test
67+ @ DisplayName ("withHubVault returns the builder for chaining" )
68+ public void withHubVaultReturnsBuilderForChaining () {
69+ Vault .Builder builder = minimalVaultBuilder ();
70+ Vault .Builder returned = builder .withHubVault (true );
71+
72+ assertThat (returned , is (builder ));
73+ }
74+ }
75+
76+ @ Nested
77+ @ DisplayName ("hubPaidLicense field" )
78+ class HubPaidLicenseField {
79+
80+ @ Test
81+ @ DisplayName ("Default hubPaidLicense is false when not set" )
82+ public void defaultHubPaidLicenseIsFalse () {
83+ Vault vault = minimalVaultBuilder ().build ();
84+
85+ assertFalse (vault .hasHubPaidLicense ());
86+ }
87+
88+ @ Test
89+ @ DisplayName ("withHubPaidLicense(true) sets hasHubPaidLicense() to true" )
90+ public void withHubPaidLicenseTrueSetsHubPaidLicenseTrue () {
91+ Vault vault = minimalVaultBuilder ()
92+ .withHubPaidLicense (true )
93+ .build ();
94+
95+ assertTrue (vault .hasHubPaidLicense ());
96+ }
97+
98+ @ Test
99+ @ DisplayName ("withHubPaidLicense(false) sets hasHubPaidLicense() to false" )
100+ public void withHubPaidLicenseFalseSetsHubPaidLicenseFalse () {
101+ Vault vault = minimalVaultBuilder ()
102+ .withHubPaidLicense (false )
103+ .build ();
104+
105+ assertFalse (vault .hasHubPaidLicense ());
106+ }
107+
108+ @ Test
109+ @ DisplayName ("withHubPaidLicense returns the builder for chaining" )
110+ public void withHubPaidLicenseReturnsBuilderForChaining () {
111+ Vault .Builder builder = minimalVaultBuilder ();
112+ Vault .Builder returned = builder .withHubPaidLicense (true );
113+
114+ assertThat (returned , is (builder ));
115+ }
116+ }
117+
118+ @ Nested
119+ @ DisplayName ("Hub vault combined state" )
120+ class HubVaultCombinedState {
121+
122+ @ Test
123+ @ DisplayName ("Hub vault with active paid license has both flags true" )
124+ public void hubVaultWithActivePaidLicense () {
125+ Vault vault = minimalVaultBuilder ()
126+ .withHubVault (true )
127+ .withHubPaidLicense (true )
128+ .build ();
129+
130+ assertTrue (vault .isHubVault ());
131+ assertTrue (vault .hasHubPaidLicense ());
132+ }
133+
134+ @ Test
135+ @ DisplayName ("Hub vault with inactive subscription has hubVault true and hubPaidLicense false" )
136+ public void hubVaultWithInactiveSubscription () {
137+ Vault vault = minimalVaultBuilder ()
138+ .withHubVault (true )
139+ .withHubPaidLicense (false )
140+ .build ();
141+
142+ assertTrue (vault .isHubVault ());
143+ assertFalse (vault .hasHubPaidLicense ());
144+ }
145+
146+ @ Test
147+ @ DisplayName ("Non-hub vault always has hubPaidLicense false" )
148+ public void nonHubVaultHasHubPaidLicenseFalse () {
149+ Vault vault = minimalVaultBuilder ()
150+ .withHubVault (false )
151+ .withHubPaidLicense (false )
152+ .build ();
153+
154+ assertFalse (vault .isHubVault ());
155+ assertFalse (vault .hasHubPaidLicense ());
156+ }
157+ }
158+
159+ @ Nested
160+ @ DisplayName ("aCopyOf preserves hub fields" )
161+ class ACopyOfPreservesHubFields {
162+
163+ @ Test
164+ @ DisplayName ("aCopyOf preserves hubVault=true" )
165+ public void aCopyOfPreservesHubVaultTrue () {
166+ Vault original = minimalVaultBuilder ()
167+ .withHubVault (true )
168+ .build ();
169+
170+ Vault copy = Vault .aCopyOf (original ).build ();
171+
172+ assertTrue (copy .isHubVault ());
173+ }
174+
175+ @ Test
176+ @ DisplayName ("aCopyOf preserves hubVault=false" )
177+ public void aCopyOfPreservesHubVaultFalse () {
178+ Vault original = minimalVaultBuilder ()
179+ .withHubVault (false )
180+ .build ();
181+
182+ Vault copy = Vault .aCopyOf (original ).build ();
183+
184+ assertFalse (copy .isHubVault ());
185+ }
186+
187+ @ Test
188+ @ DisplayName ("aCopyOf preserves hubPaidLicense=true" )
189+ public void aCopyOfPreservesHubPaidLicenseTrue () {
190+ Vault original = minimalVaultBuilder ()
191+ .withHubPaidLicense (true )
192+ .build ();
193+
194+ Vault copy = Vault .aCopyOf (original ).build ();
195+
196+ assertTrue (copy .hasHubPaidLicense ());
197+ }
198+
199+ @ Test
200+ @ DisplayName ("aCopyOf preserves hubPaidLicense=false" )
201+ public void aCopyOfPreservesHubPaidLicenseFalse () {
202+ Vault original = minimalVaultBuilder ()
203+ .withHubPaidLicense (false )
204+ .build ();
205+
206+ Vault copy = Vault .aCopyOf (original ).build ();
207+
208+ assertFalse (copy .hasHubPaidLicense ());
209+ }
210+
211+ @ Test
212+ @ DisplayName ("aCopyOf then withHubVault overrides the copied value" )
213+ public void aCopyOfThenWithHubVaultOverridesValue () {
214+ Vault original = minimalVaultBuilder ()
215+ .withHubVault (false )
216+ .build ();
217+
218+ Vault copy = Vault .aCopyOf (original )
219+ .withHubVault (true )
220+ .build ();
221+
222+ assertTrue (copy .isHubVault ());
223+ }
224+
225+ @ Test
226+ @ DisplayName ("aCopyOf then withHubPaidLicense overrides the copied value" )
227+ public void aCopyOfThenWithHubPaidLicenseOverridesValue () {
228+ Vault original = minimalVaultBuilder ()
229+ .withHubPaidLicense (false )
230+ .build ();
231+
232+ Vault copy = Vault .aCopyOf (original )
233+ .withHubPaidLicense (true )
234+ .build ();
235+
236+ assertTrue (copy .hasHubPaidLicense ());
237+ }
238+
239+ @ Test
240+ @ DisplayName ("aCopyOf preserves both hub flags together" )
241+ public void aCopyOfPreservesBothHubFlagsTogether () {
242+ Vault original = minimalVaultBuilder ()
243+ .withHubVault (true )
244+ .withHubPaidLicense (true )
245+ .build ();
246+
247+ Vault copy = Vault .aCopyOf (original ).build ();
248+
249+ assertTrue (copy .isHubVault ());
250+ assertTrue (copy .hasHubPaidLicense ());
251+ }
252+
253+ @ Test
254+ @ DisplayName ("aCopyOf preserves other original properties alongside hub fields" )
255+ public void aCopyOfPreservesOtherPropertiesAlongsideHubFields () {
256+ Vault original = Vault .aVault ()
257+ .withId (42L )
258+ .withName ("MyHub" )
259+ .withPath ("/hub/path" )
260+ .withCloud (cloud )
261+ .withPosition (3 )
262+ .withHubVault (true )
263+ .withHubPaidLicense (true )
264+ .build ();
265+
266+ Vault copy = Vault .aCopyOf (original ).build ();
267+
268+ assertThat (copy .getId (), is (42L ));
269+ assertThat (copy .getName (), is ("MyHub" ));
270+ assertThat (copy .getPath (), is ("/hub/path" ));
271+ assertThat (copy .getPosition (), is (3 ));
272+ assertTrue (copy .isHubVault ());
273+ assertTrue (copy .hasHubPaidLicense ());
274+ }
275+ }
276+ }
0 commit comments