Skip to content

Commit

Permalink
Fix reflective access in test classes (#3322)
Browse files Browse the repository at this point in the history
* Fix illegal LogManager reflective access

* Fix illegal reflective access to java.io.File with annotations
  • Loading branch information
RoiEXLab authored and ssoloff committed Mar 27, 2018
1 parent f92477e commit 0c71798
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Spy;

import com.example.mockito.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public final class LoggingConfigurationTest {
@Spy
private final LogManager logManager = LogManager.getLogManager();
@Mock
private LogManager logManager;

private final Properties systemProperties = new Properties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public final class ClientFileSystemHelperTest {
@ExtendWith(MockitoExtension.class)
@Nested
public final class GetFolderContainingFileWithNameTest {
@Spy
private final File file = new File("filename.ext");
@Mock
private File file;

@Spy
private final File parentFolder = new File("parent");
@Mock
private File parentFolder;

@Spy
private final File startFolder = new File("start");
@Mock
private File startFolder;

private File getFolderContainingFileWithName() throws Exception {
return ClientFileSystemHelper.getFolderContainingFileWithName(file.getName(), startFolder);
Expand All @@ -40,6 +40,9 @@ private File getFolderContainingFileWithName() throws Exception {
public void setUp() {
when(file.isFile()).thenReturn(true);
when(startFolder.getParentFile()).thenReturn(parentFolder);
when(file.getName()).thenReturn("filename.ext");
when(parentFolder.getName()).thenReturn("parent");
when(startFolder.getName()).thenReturn("start");
}

@Test
Expand Down
5 changes: 3 additions & 2 deletions game-core/src/test/java/games/strategy/io/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Spy;

import com.example.mockito.MockitoExtension;
Expand All @@ -19,8 +20,8 @@ public final class FileUtilsTest {
@ExtendWith(MockitoExtension.class)
@Nested
public final class ListFilesTest {
@Spy
private final File directory = new File("");
@Mock
private File directory;

@Test
public void shouldReturnFileCollectionWhenTargetIsDirectory() {
Expand Down

0 comments on commit 0c71798

Please sign in to comment.