File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change
1
+ import org.junit.jupiter.api.Test
2
+
1
3
interface File {
2
4
fun read (name : String )
3
5
}
@@ -7,8 +9,7 @@ class NormalFile : File {
7
9
}
8
10
9
11
// Proxy:
10
- class SecuredFile : File {
11
- val normalFile = NormalFile ()
12
+ class SecuredFile (private val normalFile : File ) : File {
12
13
var password: String = " "
13
14
14
15
override fun read (name : String ) {
@@ -21,10 +22,15 @@ class SecuredFile : File {
21
22
}
22
23
}
23
24
24
- fun main (args : Array <String >) {
25
- val securedFile = SecuredFile ()
26
- securedFile.read(" readme.md" )
25
+ class ProtectionProxyTest {
26
+ @Test
27
+ fun `Protection Proxy` () {
28
+ val securedFile = SecuredFile (NormalFile ())
27
29
28
- securedFile.password = " secret"
29
- securedFile.read(" readme.md" )
30
+ with (securedFile) {
31
+ read(" readme.md" )
32
+ password = " secret"
33
+ read(" readme.md" )
34
+ }
35
+ }
30
36
}
You can’t perform that action at this time.
0 commit comments