7
7
import org .cryptomator .cryptolib .api .FileContentCryptor ;
8
8
import org .cryptomator .cryptolib .api .FileHeaderCryptor ;
9
9
import org .junit .jupiter .api .Assertions ;
10
- import org .junit .jupiter .api .BeforeAll ;
10
+ import org .junit .jupiter .api .BeforeEach ;
11
11
import org .junit .jupiter .api .DisplayName ;
12
12
import org .junit .jupiter .api .Nested ;
13
- import org .junit .jupiter .api .TestInstance ;
14
13
import org .junit .jupiter .params .ParameterizedTest ;
15
14
import org .junit .jupiter .params .provider .CsvSource ;
16
15
17
16
import java .nio .file .attribute .DosFileAttributes ;
18
17
import java .util .Optional ;
19
18
20
19
import static org .cryptomator .cryptofs .common .CiphertextFileType .FILE ;
20
+ import static org .mockito .Mockito .atMostOnce ;
21
21
import static org .mockito .Mockito .mock ;
22
+ import static org .mockito .Mockito .times ;
23
+ import static org .mockito .Mockito .verify ;
22
24
import static org .mockito .Mockito .when ;
23
25
24
- @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
25
26
public class CryptoDosFileAttributesTest {
26
27
27
28
private DosFileAttributes delegate = mock (DosFileAttributes .class );
@@ -32,9 +33,9 @@ public class CryptoDosFileAttributesTest {
32
33
private OpenCryptoFile openCryptoFile = mock (OpenCryptoFile .class );
33
34
private CryptoFileSystemProperties cryptoFileSystemProperties = mock (CryptoFileSystemProperties .class );
34
35
35
- @ BeforeAll
36
+ @ BeforeEach
36
37
public void setup () {
37
- when (delegate .size ()).thenReturn (0l );
38
+ when (delegate .size ()).thenReturn (0L );
38
39
when (cryptor .fileHeaderCryptor ()).thenReturn (headerCryptor );
39
40
when (cryptor .fileContentCryptor ()).thenReturn (contentCryptor );
40
41
when (headerCryptor .headerSize ()).thenReturn (0 );
@@ -43,77 +44,85 @@ public void setup() {
43
44
}
44
45
45
46
@ Nested
46
- @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
47
47
@ DisplayName ("on read-write filesystem" )
48
48
public class ReadWriteFileSystem {
49
49
50
50
private CryptoDosFileAttributes inTest ;
51
51
52
- @ BeforeAll
53
- public void setup () {
52
+ @ BeforeEach
53
+ public void beforeEach () {
54
54
when (cryptoFileSystemProperties .readonly ()).thenReturn (false );
55
- inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
56
55
}
57
56
58
57
@ DisplayName ("isArchive()" )
59
58
@ ParameterizedTest (name = "is {0} if delegate.isArchive() is {0}" )
60
59
@ CsvSource ({"true" , "false" })
61
- public void testIsArchiveDelegates (boolean value ) {
60
+ public void testIsArchiveImmutable (boolean value ) {
62
61
when (delegate .isArchive ()).thenReturn (value );
62
+ inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
63
63
64
- Assertions .assertSame (value , inTest .isArchive ());
64
+ verify (delegate , times (1 )).isArchive ();
65
+ Assertions .assertEquals (value , inTest .isArchive ());
66
+ verify (delegate , times (1 )).isArchive ();
65
67
}
66
68
67
69
@ DisplayName ("isHidden()" )
68
70
@ ParameterizedTest (name = "is {0} if delegate.isHidden() is {0}" )
69
71
@ CsvSource ({"true" , "false" })
70
- public void testIsHiddenDelegates (boolean value ) {
72
+ public void testIsHiddenImmutable (boolean value ) {
71
73
when (delegate .isHidden ()).thenReturn (value );
74
+ inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
72
75
73
- Assertions .assertSame (value , inTest .isHidden ());
76
+ verify (delegate , times (1 )).isHidden ();
77
+ Assertions .assertEquals (value , inTest .isHidden ());
78
+ verify (delegate , times (1 )).isHidden ();
74
79
}
75
80
76
81
@ DisplayName ("isReadOnly()" )
77
82
@ ParameterizedTest (name = "is {0} if delegate.readOnly() is {0}" )
78
83
@ CsvSource ({"true" , "false" })
79
- public void testIsReadOnlyDelegates (boolean value ) {
84
+ public void testIsReadOnlyImmutable (boolean value ) {
80
85
when (delegate .isReadOnly ()).thenReturn (value );
86
+ inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
81
87
82
- Assertions .assertSame (value , inTest .isReadOnly ());
88
+ verify (delegate , times (1 )).isReadOnly ();
89
+ Assertions .assertEquals (value , inTest .isReadOnly ());
90
+ verify (delegate , times (1 )).isReadOnly ();
83
91
}
84
92
85
93
@ DisplayName ("isSystem()" )
86
94
@ ParameterizedTest (name = "is {0} if delegate.isSystem() is {0}" )
87
95
@ CsvSource ({"true" , "false" })
88
- public void testIsSystemDelegates (boolean value ) {
96
+ public void testIsSystemImmutable (boolean value ) {
89
97
when (delegate .isSystem ()).thenReturn (value );
98
+ inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
90
99
91
- Assertions .assertSame (value , inTest .isSystem ());
100
+ verify (delegate , times (1 )).isSystem ();
101
+ Assertions .assertEquals (value , inTest .isSystem ());
102
+ verify (delegate , times (1 )).isSystem ();
92
103
}
93
104
94
105
}
95
106
96
107
@ Nested
97
- @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
98
108
@ DisplayName ("on read-only filesystem" )
99
109
public class ReadOnlyFileSystem {
100
110
101
- private CryptoDosFileAttributes inTest ;
102
-
103
- @ BeforeAll
104
- public void setup () {
111
+ @ BeforeEach
112
+ public void beforeEach () {
105
113
when (cryptoFileSystemProperties .readonly ()).thenReturn (true );
106
- inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
107
114
}
108
115
109
116
@ DisplayName ("isReadOnly()" )
110
117
@ ParameterizedTest (name = "is true if delegate.readOnly() is {0}" )
111
118
@ CsvSource ({"true" , "false" })
112
119
public void testIsReadOnlyForReadonlyFileSystem (boolean value ) {
113
120
when (delegate .isReadOnly ()).thenReturn (value );
121
+ var inTest = new CryptoDosFileAttributes (delegate , FILE , path , cryptor , Optional .of (openCryptoFile ), cryptoFileSystemProperties );
114
122
123
+ verify (delegate , atMostOnce ()).isReadOnly ();
115
124
Assertions .assertTrue (inTest .isReadOnly ());
125
+ verify (delegate , atMostOnce ()).isReadOnly ();
116
126
}
117
-
118
127
}
119
128
}
0 commit comments