Skip to content

Commit 3623a39

Browse files
CodeRabbit Generated Unit Tests: Add unit tests for PR changes
1 parent dc3e70f commit 3623a39

2 files changed

Lines changed: 861 additions & 0 deletions

File tree

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
package org.cryptomator.domain;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Nested;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.hamcrest.CoreMatchers.is;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
import static org.mockito.Mockito.mock;
10+
import static org.mockito.Mockito.when;
11+
12+
public class VaultTest {
13+
14+
private static Vault buildMinimalVault() {
15+
Cloud cloud = mock(Cloud.class);
16+
when(cloud.type()).thenReturn(CloudType.WEBDAV);
17+
return Vault.aVault()
18+
.withId(1L)
19+
.withName("Test")
20+
.withPath("/test")
21+
.withCloud(cloud)
22+
.withPosition(0)
23+
.build();
24+
}
25+
26+
private static Vault.Builder minimalVaultBuilder() {
27+
Cloud cloud = mock(Cloud.class);
28+
when(cloud.type()).thenReturn(CloudType.WEBDAV);
29+
return Vault.aVault()
30+
.withId(1L)
31+
.withName("Test")
32+
.withPath("/test")
33+
.withCloud(cloud)
34+
.withPosition(0);
35+
}
36+
37+
@Nested
38+
@DisplayName("Hub fields - default values")
39+
class DefaultValues {
40+
41+
@Test
42+
@DisplayName("isHubVault defaults to false when not set")
43+
void isHubVaultDefaultsFalse() {
44+
Vault vault = buildMinimalVault();
45+
46+
assertThat(vault.isHubVault(), is(false));
47+
}
48+
49+
@Test
50+
@DisplayName("hasHubPaidLicense defaults to false when not set")
51+
void hasHubPaidLicenseDefaultsFalse() {
52+
Vault vault = buildMinimalVault();
53+
54+
assertThat(vault.hasHubPaidLicense(), is(false));
55+
}
56+
}
57+
58+
@Nested
59+
@DisplayName("Hub fields - builder setter")
60+
class BuilderSetters {
61+
62+
@Test
63+
@DisplayName("withHubVault(true) sets isHubVault to true")
64+
void withHubVaultTrue() {
65+
Vault vault = minimalVaultBuilder()
66+
.withHubVault(true)
67+
.build();
68+
69+
assertThat(vault.isHubVault(), is(true));
70+
}
71+
72+
@Test
73+
@DisplayName("withHubVault(false) keeps isHubVault false")
74+
void withHubVaultFalse() {
75+
Vault vault = minimalVaultBuilder()
76+
.withHubVault(false)
77+
.build();
78+
79+
assertThat(vault.isHubVault(), is(false));
80+
}
81+
82+
@Test
83+
@DisplayName("withHubPaidLicense(true) sets hasHubPaidLicense to true")
84+
void withHubPaidLicenseTrue() {
85+
Vault vault = minimalVaultBuilder()
86+
.withHubPaidLicense(true)
87+
.build();
88+
89+
assertThat(vault.hasHubPaidLicense(), is(true));
90+
}
91+
92+
@Test
93+
@DisplayName("withHubPaidLicense(false) keeps hasHubPaidLicense false")
94+
void withHubPaidLicenseFalse() {
95+
Vault vault = minimalVaultBuilder()
96+
.withHubPaidLicense(false)
97+
.build();
98+
99+
assertThat(vault.hasHubPaidLicense(), is(false));
100+
}
101+
102+
@Test
103+
@DisplayName("withHubVault and withHubPaidLicense can both be set independently")
104+
void hubVaultAndPaidLicenseAreIndependent() {
105+
Vault vaultHubOnly = minimalVaultBuilder()
106+
.withHubVault(true)
107+
.withHubPaidLicense(false)
108+
.build();
109+
Vault vaultPaidOnly = minimalVaultBuilder()
110+
.withHubVault(false)
111+
.withHubPaidLicense(true)
112+
.build();
113+
Vault vaultBoth = minimalVaultBuilder()
114+
.withHubVault(true)
115+
.withHubPaidLicense(true)
116+
.build();
117+
118+
assertThat(vaultHubOnly.isHubVault(), is(true));
119+
assertThat(vaultHubOnly.hasHubPaidLicense(), is(false));
120+
121+
assertThat(vaultPaidOnly.isHubVault(), is(false));
122+
assertThat(vaultPaidOnly.hasHubPaidLicense(), is(true));
123+
124+
assertThat(vaultBoth.isHubVault(), is(true));
125+
assertThat(vaultBoth.hasHubPaidLicense(), is(true));
126+
}
127+
}
128+
129+
@Nested
130+
@DisplayName("aCopyOf - hub field propagation")
131+
class CopyOf {
132+
133+
@Test
134+
@DisplayName("aCopyOf preserves isHubVault=false")
135+
void copyPreservesHubVaultFalse() {
136+
Vault original = buildMinimalVault();
137+
138+
Vault copy = Vault.aCopyOf(original).build();
139+
140+
assertThat(copy.isHubVault(), is(false));
141+
}
142+
143+
@Test
144+
@DisplayName("aCopyOf preserves isHubVault=true")
145+
void copyPreservesHubVaultTrue() {
146+
Vault original = minimalVaultBuilder()
147+
.withHubVault(true)
148+
.build();
149+
150+
Vault copy = Vault.aCopyOf(original).build();
151+
152+
assertThat(copy.isHubVault(), is(true));
153+
}
154+
155+
@Test
156+
@DisplayName("aCopyOf preserves hasHubPaidLicense=false")
157+
void copyPreservesHubPaidLicenseFalse() {
158+
Vault original = buildMinimalVault();
159+
160+
Vault copy = Vault.aCopyOf(original).build();
161+
162+
assertThat(copy.hasHubPaidLicense(), is(false));
163+
}
164+
165+
@Test
166+
@DisplayName("aCopyOf preserves hasHubPaidLicense=true")
167+
void copyPreservesHubPaidLicenseTrue() {
168+
Vault original = minimalVaultBuilder()
169+
.withHubPaidLicense(true)
170+
.build();
171+
172+
Vault copy = Vault.aCopyOf(original).build();
173+
174+
assertThat(copy.hasHubPaidLicense(), is(true));
175+
}
176+
177+
@Test
178+
@DisplayName("aCopyOf allows overriding isHubVault after copy")
179+
void copyAllowsOverridingHubVault() {
180+
Vault original = minimalVaultBuilder()
181+
.withHubVault(false)
182+
.build();
183+
184+
Vault modified = Vault.aCopyOf(original)
185+
.withHubVault(true)
186+
.build();
187+
188+
assertThat(modified.isHubVault(), is(true));
189+
}
190+
191+
@Test
192+
@DisplayName("aCopyOf allows overriding hasHubPaidLicense after copy")
193+
void copyAllowsOverridingHubPaidLicense() {
194+
Vault original = minimalVaultBuilder()
195+
.withHubPaidLicense(false)
196+
.build();
197+
198+
Vault modified = Vault.aCopyOf(original)
199+
.withHubPaidLicense(true)
200+
.build();
201+
202+
assertThat(modified.hasHubPaidLicense(), is(true));
203+
}
204+
205+
@Test
206+
@DisplayName("aCopyOf with both hub fields set true preserves both in copy")
207+
void copyPreservesBothHubFieldsTrue() {
208+
Vault original = minimalVaultBuilder()
209+
.withHubVault(true)
210+
.withHubPaidLicense(true)
211+
.build();
212+
213+
Vault copy = Vault.aCopyOf(original).build();
214+
215+
assertThat(copy.isHubVault(), is(true));
216+
assertThat(copy.hasHubPaidLicense(), is(true));
217+
}
218+
219+
@Test
220+
@DisplayName("aCopyOf does not mutate the original vault")
221+
void copyDoesNotMutateOriginal() {
222+
Vault original = minimalVaultBuilder()
223+
.withHubVault(false)
224+
.withHubPaidLicense(false)
225+
.build();
226+
227+
Vault.aCopyOf(original)
228+
.withHubVault(true)
229+
.withHubPaidLicense(true)
230+
.build();
231+
232+
assertThat(original.isHubVault(), is(false));
233+
assertThat(original.hasHubPaidLicense(), is(false));
234+
}
235+
}
236+
237+
@Nested
238+
@DisplayName("Hub fields - regression: non-hub vaults remain unaffected")
239+
class NonHubVaultRegression {
240+
241+
@Test
242+
@DisplayName("Standard vault without hub flags has false for both")
243+
void standardVaultHasFalseForBothHubFlags() {
244+
Cloud cloud = mock(Cloud.class);
245+
when(cloud.type()).thenReturn(CloudType.S3);
246+
Vault vault = Vault.aVault()
247+
.withId(42L)
248+
.withName("MyVault")
249+
.withPath("/s3/my-vault")
250+
.withCloud(cloud)
251+
.withPosition(3)
252+
.build();
253+
254+
assertThat(vault.isHubVault(), is(false));
255+
assertThat(vault.hasHubPaidLicense(), is(false));
256+
}
257+
}
258+
}

0 commit comments

Comments
 (0)