Skip to content

Commit

Permalink
http-service: update tests to junit 5
Browse files Browse the repository at this point in the history
The junit 4 tests do not get picked up and ran automatically
  • Loading branch information
Adam- committed Feb 14, 2025
1 parent aef8dd6 commit c0c6b84
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import net.runelite.http.api.config.ConfigPatch;
import net.runelite.http.service.account.AuthFilter;
import net.runelite.http.service.account.beans.SessionEntry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -45,12 +45,12 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@WebMvcTest(ConfigController.class)
@ActiveProfiles("test")
public class ConfigControllerTest
Expand All @@ -64,7 +64,7 @@ public class ConfigControllerTest
@MockBean
private AuthFilter authFilter;

@Before
@BeforeEach
public void before() throws IOException
{
when(authFilter.handle(any(HttpServletRequest.class), any(HttpServletResponse.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
package net.runelite.http.service.item;

import java.time.Instant;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ItemServiceTest
{
@Test
public void testParseHeaderDate()
{
Instant instant = ItemService.parseHeaderDate("ID,Current Cost (as of 02-Nov-2022 10:52)");
assertEquals(Instant.parse("2022-11-02T10:52:00Z"), instant);
Assertions.assertEquals(Instant.parse("2022-11-02T10:52:00Z"), instant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.sql2o.tools.IOUtils;

public class WorldsServiceTest
{
@Rule
public final MockWebServer server = new MockWebServer();
private MockWebServer server;

@Before
public void before() throws IOException
@BeforeEach
void before() throws IOException
{
server = new MockWebServer();

InputStream in = WorldsServiceTest.class.getResourceAsStream("worldlist");
byte[] worldData = IOUtils.toByteArray(in);

Expand All @@ -58,6 +59,12 @@ public void before() throws IOException
server.enqueue(new MockResponse().setBody(buffer));
}

@AfterEach
void after() throws IOException
{
server.shutdown();
}

@Test
public void testListWorlds() throws Exception
{
Expand Down

0 comments on commit c0c6b84

Please sign in to comment.