18
18
19
19
package pl .project13 .maven .git ;
20
20
21
- import static org .junit .Assert .assertEquals ;
21
+ import static org .junit .jupiter . api . Assertions .assertEquals ;
22
22
23
23
import java .io .File ;
24
+ import java .nio .file .Path ;
24
25
import org .eclipse .jgit .api .Git ;
25
26
import org .eclipse .jgit .lib .ConfigConstants ;
26
27
import org .eclipse .jgit .lib .StoredConfig ;
27
- import org .junit .After ;
28
- import org .junit .Before ;
29
- import org .junit .Rule ;
30
- import org .junit .Test ;
31
- import org .junit .rules .TemporaryFolder ;
28
+ import org .junit .jupiter .api .AfterEach ;
29
+ import org .junit .jupiter .api .BeforeEach ;
30
+ import org .junit .jupiter .api .Test ;
31
+ import org .junit .jupiter .api .io .TempDir ;
32
32
import pl .project13 .core .AheadBehind ;
33
33
import pl .project13 .core .GitProvider ;
34
34
37
37
*/
38
38
public abstract class AheadBehindTest <T extends GitProvider > {
39
39
40
- @ Rule public TemporaryFolder remoteRepository = new TemporaryFolder ();
40
+ @ TempDir
41
+ public Path remoteRepository ;
41
42
42
- @ Rule public TemporaryFolder localRepository = new TemporaryFolder ();
43
+ @ TempDir
44
+ public Path localRepository ;
43
45
44
- @ Rule public TemporaryFolder secondLocalRepository = new TemporaryFolder ();
46
+ @ TempDir
47
+ public Path secondLocalRepository ;
45
48
46
49
protected Git localRepositoryGit ;
47
50
48
51
protected Git secondLocalRepositoryGit ;
49
52
50
53
protected T gitProvider ;
51
54
52
- @ Before
55
+ @ BeforeEach
53
56
public void setup () throws Exception {
54
57
55
58
createRemoteRepository ();
@@ -65,7 +68,7 @@ public void setup() throws Exception {
65
68
extraSetup ();
66
69
}
67
70
68
- @ After
71
+ @ AfterEach
69
72
public void tearDown () throws Exception {
70
73
if (localRepositoryGit != null ) {
71
74
localRepositoryGit .close ();
@@ -122,30 +125,30 @@ public void shouldBe1AheadAnd1Behind() throws Exception {
122
125
}
123
126
124
127
protected void createLocalCommit () throws Exception {
125
- File newFile = localRepository .newFile ();
128
+ File newFile = localRepository .toFile ();
126
129
localRepositoryGit .add ().addFilepattern (newFile .getName ()).call ();
127
130
localRepositoryGit .commit ().setMessage ("ahead" ).call ();
128
131
}
129
132
130
133
protected void createCommitInSecondRepoAndPush () throws Exception {
131
134
secondLocalRepositoryGit .pull ().call ();
132
135
133
- File newFile = secondLocalRepository .newFile ();
136
+ File newFile = secondLocalRepository .toFile ();
134
137
secondLocalRepositoryGit .add ().addFilepattern (newFile .getName ()).call ();
135
138
secondLocalRepositoryGit .commit ().setMessage ("behind" ).call ();
136
139
137
140
secondLocalRepositoryGit .push ().call ();
138
141
}
139
142
140
143
protected void createRemoteRepository () throws Exception {
141
- Git .init ().setBare (true ).setDirectory (remoteRepository .getRoot ()).call ();
144
+ Git .init ().setBare (true ).setDirectory (remoteRepository .toFile ()).call ();
142
145
}
143
146
144
147
protected void setupLocalRepository () throws Exception {
145
148
localRepositoryGit =
146
149
Git .cloneRepository ()
147
- .setURI (remoteRepository .getRoot ().toURI ().toString ())
148
- .setDirectory (localRepository .getRoot ())
150
+ .setURI (remoteRepository .toFile ().toURI ().toString ())
151
+ .setDirectory (localRepository .toFile ())
149
152
.setBranch ("master" )
150
153
.call ();
151
154
@@ -158,14 +161,14 @@ protected void setupLocalRepository() throws Exception {
158
161
protected void setupSecondLocalRepository () throws Exception {
159
162
secondLocalRepositoryGit =
160
163
Git .cloneRepository ()
161
- .setURI (remoteRepository .getRoot ().toURI ().toString ())
162
- .setDirectory (secondLocalRepository .getRoot ())
164
+ .setURI (remoteRepository .toFile ().toURI ().toString ())
165
+ .setDirectory (secondLocalRepository .toFile ())
163
166
.setBranch ("master" )
164
167
.call ();
165
168
}
166
169
167
170
protected void createAndPushInitialCommit () throws Exception {
168
- File newFile = localRepository .newFile ();
171
+ File newFile = localRepository .toFile ();
169
172
localRepositoryGit .add ().addFilepattern (newFile .getName ()).call ();
170
173
localRepositoryGit .commit ().setMessage ("initial" ).call ();
171
174
0 commit comments