3030import java .util .Date ;
3131import java .util .concurrent .TimeUnit ;
3232import org .junit .Before ;
33+ import org .junit .Rule ;
3334import org .junit .Test ;
3435import org .junit .experimental .runners .Enclosed ;
36+ import org .junit .rules .TemporaryFolder ;
3537import org .junit .runner .RunWith ;
3638import org .junit .runners .JUnit4 ;
3739
4042public class JwtTokenFileCallCredentialsTest {
4143 @ RunWith (JUnit4 .class )
4244 public static class WithEmptyJwtTokenTest {
45+ @ Rule
46+ public TemporaryFolder tempFolder = new TemporaryFolder ();
47+
4348 private File jwtTokenFile ;
4449 private JwtTokenFileCallCredentials unit ;
4550
4651 @ Before
4752 public void setUp () throws Exception {
48- this .jwtTokenFile = JwtTokenFileTestUtils . createEmptyJwtToken ( );
53+ this .jwtTokenFile = tempFolder . newFile ( "empty_jwt.token" );
4954
5055 Constructor <JwtTokenFileCallCredentials > ctor =
5156 JwtTokenFileCallCredentials .class .getDeclaredConstructor (String .class );
@@ -63,12 +68,16 @@ public void givenJwtTokenFileEmpty_WhenTokenRefreshed_ExpectException() {
6368
6469 @ RunWith (JUnit4 .class )
6570 public static class WithInvalidJwtTokenTest {
71+ @ Rule
72+ public TemporaryFolder tempFolder = new TemporaryFolder ();
73+
6674 private File jwtTokenFile ;
6775 private JwtTokenFileCallCredentials unit ;
6876
6977 @ Before
7078 public void setUp () throws Exception {
71- this .jwtTokenFile = JwtTokenFileTestUtils .createJwtTokenWithoutExpiration ();
79+ this .jwtTokenFile = tempFolder .newFile ("invalid_jwt.token" );
80+ JwtTokenFileTestUtils .writeJwtTokenContentWithoutExpiration (jwtTokenFile );
7281
7382 Constructor <JwtTokenFileCallCredentials > ctor =
7483 JwtTokenFileCallCredentials .class .getDeclaredConstructor (String .class );
@@ -92,15 +101,19 @@ public void givenJwtTokenFileWithoutExpiration_WhenTokenRefreshed_ExpectExceptio
92101
93102 @ RunWith (JUnit4 .class )
94103 public static class WithValidJwtTokenTest {
104+ @ Rule
105+ public TemporaryFolder tempFolder = new TemporaryFolder ();
106+
95107 private File jwtTokenFile ;
96108 private JwtTokenFileCallCredentials unit ;
97109 private Long givenExpTimeInSeconds ;
98110
99111 @ Before
100112 public void setUp () throws Exception {
113+ this .jwtTokenFile = tempFolder .newFile ("jwt.token" );
101114 this .givenExpTimeInSeconds = Instant .now ().getEpochSecond () + TimeUnit .HOURS .toSeconds (1 );
102-
103- this . jwtTokenFile = JwtTokenFileTestUtils .createValidJwtToken ( givenExpTimeInSeconds );
115+
116+ JwtTokenFileTestUtils .writeValidJwtTokenContent ( jwtTokenFile , givenExpTimeInSeconds );
104117
105118 Constructor <JwtTokenFileCallCredentials > ctor =
106119 JwtTokenFileCallCredentials .class .getDeclaredConstructor (String .class );
0 commit comments