88import org .junit .jupiter .api .Test ;
99import org .junit .jupiter .api .extension .ExtendWith ;
1010import org .junit .jupiter .api .io .TempDir ;
11+ import org .mockito .Mock ;
1112import uk .org .webcompere .systemstubs .jupiter .SystemStub ;
1213import uk .org .webcompere .systemstubs .jupiter .SystemStubsExtension ;
1314import uk .org .webcompere .systemstubs .stream .SystemOut ;
@@ -31,17 +32,17 @@ class GobPieConfTest {
3132 private Path tempDir ;
3233 @ SystemStub
3334 private SystemOut systemOut ;
34- MagpieServer magpieServer ;
35- GobPieConfReader gobPieConfReader ;
35+
36+ @ Mock
37+ MagpieServer magpieServer = mock (MagpieServer .class );
3638
3739 /*
3840 * A function that mocks MagpieServer, gets absolute
3941 * file path and returns new GobPieConfReader.
4042 */
4143 GobPieConfReader preFileSetup (Integer fileNumber ) {
4244 // Mock everything needed for creating GobPieConfReader
43- MagpieServer magpieServer = mock (MagpieServer .class );
44- String fileName = "gobpieTest" + Integer .toString (fileNumber ) + ".json" ;
45+ String fileName = "gobpieTest" + fileNumber + ".json" ;
4546 String gobPieConfFileName = GobPieConfTest .class .getResource (fileName ).getFile ();
4647 return new GobPieConfReader (magpieServer , gobPieConfFileName );
4748 }
@@ -52,7 +53,7 @@ GobPieConfReader preFileSetup(Integer fileNumber) {
5253 */
5354 @ Test
5455 void testReadGobPieConfiguration () {
55- gobPieConfReader = preFileSetup (1 );
56+ GobPieConfReader gobPieConfReader = preFileSetup (1 );
5657 GobPieConfiguration expectedGobPieConfiguration =
5758 new GobPieConfiguration .Builder ()
5859 .setGoblintConf ("goblint.json" )
@@ -76,7 +77,7 @@ void testReadGobPieConfiguration() {
7677 */
7778 @ Test
7879 void testReadCompleteGobPieConfiguration () {
79- gobPieConfReader = preFileSetup (2 );
80+ GobPieConfReader gobPieConfReader = preFileSetup (2 );
8081 GobPieConfiguration expectedGobPieConfiguration =
8182 new GobPieConfiguration .Builder ()
8283 .setGoblintConf ("goblint.json" )
@@ -100,7 +101,7 @@ void testReadCompleteGobPieConfiguration() {
100101 */
101102 @ Test
102103 void testGobPieConfigurationDefaultValues () {
103- gobPieConfReader = preFileSetup (3 );
104+ GobPieConfReader gobPieConfReader = preFileSetup (3 );
104105 GobPieConfiguration expectedGobPieConfiguration =
105106 new GobPieConfiguration .Builder ()
106107 .setGoblintConf ("goblint.json" )
@@ -124,7 +125,7 @@ void testGobPieConfigurationDefaultValues() {
124125 */
125126 @ Test
126127 void testReadGobPieConfigurationWithWrongJSONSyntax () {
127- gobPieConfReader = preFileSetup (4 );
128+ GobPieConfReader gobPieConfReader = preFileSetup (4 );
128129 GobPieException thrown = assertThrows (GobPieException .class , gobPieConfReader ::readGobPieConfiguration );
129130 assertEquals ("GobPie configuration file syntax is wrong." , thrown .getMessage ());
130131 }
@@ -135,7 +136,7 @@ void testReadGobPieConfigurationWithWrongJSONSyntax() {
135136 */
136137 @ Test
137138 void testReadGobPieConfigurationWithExtraField () {
138- gobPieConfReader = preFileSetup (5 );
139+ GobPieConfReader gobPieConfReader = preFileSetup (5 );
139140 GobPieConfiguration expectedGobPieConfiguration =
140141 new GobPieConfiguration .Builder ()
141142 .setGoblintConf ("goblint.json" )
@@ -153,11 +154,11 @@ void testReadGobPieConfigurationWithExtraField() {
153154 assertEquals (expectedGobPieConfiguration , actualGobPieConfiguration );
154155 }
155156
156- /*
157+ /**
157158 * Mock test to ensure @readGobPieConfiguration function
158159 * messages user when the configuration file is absent
159160 * in the root directory
160- */
161+ ** /
161162 @ Test
162163 void testGobPieConfigurationFileMissingInRoot () throws IOException , ExecutionException , InterruptedException {
163164 // Mock everything needed for creating GobPieConfReader
@@ -260,10 +261,7 @@ void testGobPieConfigurationWithoutGoblintConfField() throws IOException, Execut
260261 */
261262 @ Test
262263 void testGobPieConfigurationWithoutGoblintConfField2 () throws ExecutionException , InterruptedException {
263- // Mock everything needed for creating GobPieConfReader
264- MagpieServer magpieServer = mock (MagpieServer .class );
265- String gobPieConfFileName = GobPieConfTest .class .getResource ("gobpieTest6.json" ).getFile ();
266- GobPieConfReader gobPieConfReader = new GobPieConfReader (magpieServer , gobPieConfFileName );
264+ GobPieConfReader gobPieConfReader = preFileSetup (6 );
267265
268266 CompletableFuture <GobPieConfiguration > future = CompletableFuture .supplyAsync (gobPieConfReader ::readGobPieConfiguration );
269267
0 commit comments