9
9
import java .io .File ;
10
10
import java .io .FileNotFoundException ;
11
11
import java .nio .file .Files ;
12
- import java .util .List ;
13
12
import java .util .function .Function ;
14
13
import java .util .stream .Stream ;
15
14
16
15
import org .assertj .core .api .Condition ;
17
16
import org .junit .jupiter .api .AfterEach ;
18
17
import org .junit .jupiter .api .BeforeEach ;
18
+ import org .junit .jupiter .api .Test ;
19
19
import org .junit .jupiter .params .ParameterizedTest ;
20
20
import org .junit .jupiter .params .provider .Arguments ;
21
21
import org .junit .jupiter .params .provider .MethodSource ;
@@ -42,14 +42,10 @@ void afterEach() {
42
42
43
43
static Stream <Arguments > readPassword () {
44
44
Function <String , PasswordProvider > filePassword = FilePassword ::new ;
45
- Function <String , PasswordProvider > filePasswordPath = FilePasswordFilePath ::new ;
46
45
return Stream .of (
47
46
Arguments .of (filePassword , "mypassword" , "mypassword" ),
48
47
Arguments .of (filePassword , "mypassword\n " , "mypassword" ),
49
- Arguments .of (filePassword , "mypassword\n ignores\n additional lines" , "mypassword" ),
50
- Arguments .of (filePasswordPath , "mypassword" , "mypassword" ),
51
- Arguments .of (filePasswordPath , "mypassword\n " , "mypassword" ),
52
- Arguments .of (filePasswordPath , "mypassword\n ignores\n additional lines" , "mypassword" ));
48
+ Arguments .of (filePassword , "mypassword\n ignores\n additional lines" , "mypassword" ));
53
49
}
54
50
55
51
@ ParameterizedTest
@@ -62,28 +58,22 @@ void readPassword(Function<String, PasswordProvider> providerFunc, String input,
62
58
.isEqualTo (expected );
63
59
}
64
60
65
- static List <Function <String , PasswordProvider >> providers () {
66
- return List .of (FilePassword ::new , FilePasswordFilePath ::new );
67
- }
68
-
69
- @ ParameterizedTest
70
- @ MethodSource ("providers" )
71
- void toStringDoesNotLeakPassword (Function <String , PasswordProvider > providerFunc ) throws Exception {
61
+ @ Test
62
+ void toStringDoesNotLeakPassword () throws Exception {
72
63
var password = "mypassword" ;
73
64
Files .writeString (file .toPath (), password );
74
- var provider = providerFunc . apply (file .getAbsolutePath ());
65
+ var provider = new FilePassword (file .getAbsolutePath ());
75
66
assertThat (provider )
76
67
.extracting (Object ::toString )
77
68
.doesNotHave (new Condition <>(s -> s .contains (password ), "contains password" ));
78
69
}
79
70
80
- @ ParameterizedTest
81
- @ MethodSource ("providers" )
82
- void passwordFileNotFound (Function <String , PasswordProvider > providerFunc ) {
71
+ @ Test
72
+ void passwordFileNotFound () {
83
73
assertThat (file .delete ()).isTrue ();
84
74
85
75
String path = file .getAbsolutePath ();
86
- var provider = providerFunc . apply ( path );
76
+ var provider = new FilePassword ( file . getAbsolutePath () );
87
77
assertThatThrownBy (provider ::getProvidedPassword )
88
78
.hasMessageContaining (path )
89
79
.hasRootCauseInstanceOf (FileNotFoundException .class );
0 commit comments