Skip to content

Commit 0b527ca

Browse files
committed
Prevent use of reflection in tests
1 parent 5f5d7cf commit 0b527ca

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ jdk:
66
- oraclejdk9
77
- openjdk8
88
# https://docs.travis-ci.com/user/reference/trusty/#jvm-clojure-groovy-java-scala-images
9-
# Oracle JDK 10 is not provided because it reached End of Life in October 2018.
9+
# - Oracle JDK 10 is not provided because it reached End of Life in October 2018.
10+
# - JDK 7 is not listed as the Sonar plugin requires Java 8. However, all JDKs compile with target version 7.
1011

1112
addons:
1213
sonarcloud:

src/test/java/me/desair/tus/server/upload/disk/FileBasedLockTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import static org.mockito.Mockito.anyBoolean;
66
import static org.mockito.Mockito.anyLong;
77
import static org.mockito.Mockito.doReturn;
8-
import static org.mockito.Mockito.mock;
8+
import static org.mockito.Mockito.spy;
99

1010
import java.io.IOException;
1111
import java.nio.channels.FileChannel;
@@ -17,13 +17,9 @@
1717
import me.desair.tus.server.exception.UploadAlreadyLockedException;
1818
import org.junit.BeforeClass;
1919
import org.junit.Test;
20-
import org.springframework.test.util.ReflectionTestUtils;
21-
2220

2321
public class FileBasedLockTest {
2422

25-
private DiskStorageService storageService;
26-
2723
private static Path storagePath;
2824

2925
@BeforeClass
@@ -92,10 +88,6 @@ public void testLockIOException() throws UploadAlreadyLockedException, IOExcepti
9288
}
9389

9490
private FileChannel createFileChannelMock() throws IOException {
95-
FileChannel channel = mock(FileChannel.class);
96-
97-
ReflectionTestUtils.setField(channel, "closeLock", new Object());
98-
ReflectionTestUtils.setField(channel, "open", true);
99-
return channel;
91+
return spy(FileChannel.class);
10092
}
10193
}

0 commit comments

Comments
 (0)