diff --git a/pom.xml b/pom.xml index 9c0809df..dd50529a 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,6 @@ UTF-8 - 1.10.19 - 4.13.2 github ${env.GH_TOKEN} 11 @@ -226,13 +224,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.1.2 - - - org.apache.maven.surefire - surefire-junit4 - 3.2.1 - - **/*.java @@ -295,16 +286,15 @@ - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter + 5.10.0 test - org.mockito - mockito-all - ${mockito.version} + mockito-junit-jupiter + 5.6.0 test diff --git a/src/test/java/com/saucelabs/ci/BrowserFactoryTest.java b/src/test/java/com/saucelabs/ci/BrowserFactoryTest.java index 65611103..30000d96 100644 --- a/src/test/java/com/saucelabs/ci/BrowserFactoryTest.java +++ b/src/test/java/com/saucelabs/ci/BrowserFactoryTest.java @@ -1,33 +1,31 @@ package com.saucelabs.ci; import com.saucelabs.saucerest.SauceREST; +import com.saucelabs.saucerest.api.PlatformEndpoint; import com.saucelabs.saucerest.model.platform.Platform; import com.saucelabs.saucerest.model.platform.SupportedPlatforms; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; -import java.nio.charset.Charset; import java.util.Collections; import java.util.List; import java.util.ArrayList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class BrowserFactoryTest { - - private static final Charset UTF_8 = Charset.forName("UTF-8"); +class BrowserFactoryTest { private BrowserFactory browserFactory; - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { // Mock appium response - List appiumPlatforms = new ArrayList(); + List appiumPlatforms = new ArrayList<>(); Platform kindle = new Platform( @@ -80,8 +78,7 @@ public void setUp() throws Exception { webdriverPlatforms.add(linux); SauceREST sauceREST = mock(SauceREST.class); - com.saucelabs.saucerest.api.PlatformEndpoint mockPlatform = - mock(com.saucelabs.saucerest.api.PlatformEndpoint.class); + PlatformEndpoint mockPlatform = mock(PlatformEndpoint.class); when(sauceREST.getPlatformEndpoint()).thenReturn(mockPlatform); @@ -95,93 +92,91 @@ public void setUp() throws Exception { } @Test - public void testGetAppiumBrowsers() throws IOException { + void testGetAppiumBrowsers() throws IOException { List browsers = this.browserFactory.getAppiumBrowsers(); assertEquals(2, browsers.size()); - int elm = 0; - assertEquals("Amazon_Kindle_Fire_Emulatorlandscapeandroid2_3_7_", browsers.get(elm).getKey()); - assertEquals("android", browsers.get(elm).getOs()); - assertEquals("android", browsers.get(elm).getBrowserName()); - assertEquals("2.3", browsers.get(elm).getVersion()); - assertEquals("Amazon Kindle Fire Emulator 2.3 (landscape)", browsers.get(elm).getName()); - assertEquals("2.3.7.", browsers.get(elm).getLongVersion()); - assertEquals("Amazon Kindle Fire Emulator", browsers.get(elm).getLongName()); - assertEquals("Amazon Kindle Fire Emulator", browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals("landscape", browsers.get(elm).getDeviceOrientation()); - - elm = 1; - assertEquals("Amazon_Kindle_Fire_Emulatorportraitandroid2_3_7_", browsers.get(elm).getKey()); - assertEquals("android", browsers.get(elm).getOs()); - assertEquals("android", browsers.get(elm).getBrowserName()); - assertEquals("2.3", browsers.get(elm).getVersion()); - assertEquals("Amazon Kindle Fire Emulator 2.3 (portrait)", browsers.get(elm).getName()); - assertEquals("2.3.7.", browsers.get(elm).getLongVersion()); - assertEquals("Amazon Kindle Fire Emulator", browsers.get(elm).getLongName()); - assertEquals("Amazon Kindle Fire Emulator", browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals("portrait", browsers.get(elm).getDeviceOrientation()); + Browser browser1 = browsers.get(0); + assertEquals("Amazon_Kindle_Fire_Emulatorlandscapeandroid2_3_7_", browser1.getKey()); + assertEquals("android", browser1.getOs()); + assertEquals("android", browser1.getBrowserName()); + assertEquals("2.3", browser1.getVersion()); + assertEquals("Amazon Kindle Fire Emulator 2.3 (landscape)", browser1.getName()); + assertEquals("2.3.7.", browser1.getLongVersion()); + assertEquals("Amazon Kindle Fire Emulator", browser1.getLongName()); + assertEquals("Amazon Kindle Fire Emulator", browser1.getDevice()); + assertNull(browser1.getDeviceType()); + assertEquals("landscape", browser1.getDeviceOrientation()); + + Browser browser2 = browsers.get(1); + assertEquals("Amazon_Kindle_Fire_Emulatorportraitandroid2_3_7_", browser2.getKey()); + assertEquals("android", browser2.getOs()); + assertEquals("android", browser2.getBrowserName()); + assertEquals("2.3", browser2.getVersion()); + assertEquals("Amazon Kindle Fire Emulator 2.3 (portrait)", browser2.getName()); + assertEquals("2.3.7.", browser2.getLongVersion()); + assertEquals("Amazon Kindle Fire Emulator", browser2.getLongName()); + assertEquals("Amazon Kindle Fire Emulator", browser2.getDevice()); + assertNull(browser2.getDeviceType()); + assertEquals("portrait", browser2.getDeviceOrientation()); } @Test - public void testGetWebDriverBrowsers() throws IOException { + void testGetWebDriverBrowsers() throws IOException { List browsers = this.browserFactory.getWebDriverBrowsers(); assertEquals(4, browsers.size()); - int elm = 0; - assertEquals( - "Amazon_Kindle_Fire_HD_8_9_Emulatorlandscapeandroid4_0_4_", browsers.get(elm).getKey()); - assertEquals("android", browsers.get(elm).getOs()); - assertEquals("android", browsers.get(elm).getBrowserName()); - assertEquals("4.0", browsers.get(elm).getVersion()); - assertEquals("Amazon Kindle Fire HD 8.9 Emulator 4.0 (landscape)", browsers.get(elm).getName()); - assertEquals("4.0.4.", browsers.get(elm).getLongVersion()); - assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browsers.get(elm).getLongName()); - assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals("landscape", browsers.get(elm).getDeviceOrientation()); - - elm = 1; - assertEquals( - "Amazon_Kindle_Fire_HD_8_9_Emulatorportraitandroid4_0_4_", browsers.get(elm).getKey()); - assertEquals("android", browsers.get(elm).getOs()); - assertEquals("android", browsers.get(elm).getBrowserName()); - assertEquals("4.0", browsers.get(elm).getVersion()); - assertEquals("Amazon Kindle Fire HD 8.9 Emulator 4.0 (portrait)", browsers.get(elm).getName()); - assertEquals("4.0.4.", browsers.get(elm).getLongVersion()); - assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browsers.get(elm).getLongName()); - assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals("portrait", browsers.get(elm).getDeviceOrientation()); - - elm = 2; - assertEquals("Linuxfirefox4", browsers.get(elm).getKey()); - assertEquals("Linux", browsers.get(elm).getOs()); - assertEquals("firefox", browsers.get(elm).getBrowserName()); - assertEquals("4", browsers.get(elm).getVersion()); - assertEquals("Linux Firefox 4", browsers.get(elm).getName()); - assertEquals("4.0.1.", browsers.get(elm).getLongVersion()); - assertEquals("Firefox", browsers.get(elm).getLongName()); - assertEquals(null, browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals(null, browsers.get(elm).getDeviceOrientation()); - - elm = 3; - assertEquals("Linuxfirefoxlatest", browsers.get(elm).getKey()); - assertEquals("Linux", browsers.get(elm).getOs()); - assertEquals("firefox", browsers.get(elm).getBrowserName()); - assertEquals("latest", browsers.get(elm).getVersion()); - assertEquals("Linux Firefox latest", browsers.get(elm).getName()); - assertEquals("latest", browsers.get(elm).getLongVersion()); - assertEquals("Firefox", browsers.get(elm).getLongName()); - assertEquals(null, browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals(null, browsers.get(elm).getDeviceOrientation()); + Browser browser1 = browsers.get(0); + assertEquals("Amazon_Kindle_Fire_HD_8_9_Emulatorlandscapeandroid4_0_4_", browser1.getKey()); + assertEquals("android", browser1.getOs()); + assertEquals("android", browser1.getBrowserName()); + assertEquals("4.0", browser1.getVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 Emulator 4.0 (landscape)", browser1.getName()); + assertEquals("4.0.4.", browser1.getLongVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browser1.getLongName()); + assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browser1.getDevice()); + assertNull(browser1.getDeviceType()); + assertEquals("landscape", browser1.getDeviceOrientation()); + + Browser browser2 = browsers.get(1); + assertEquals("Amazon_Kindle_Fire_HD_8_9_Emulatorportraitandroid4_0_4_", browser2.getKey()); + assertEquals("android", browser2.getOs()); + assertEquals("android", browser2.getBrowserName()); + assertEquals("4.0", browser2.getVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 Emulator 4.0 (portrait)", browser2.getName()); + assertEquals("4.0.4.", browser2.getLongVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browser2.getLongName()); + assertEquals("Amazon Kindle Fire HD 8.9 Emulator", browser2.getDevice()); + assertNull(browser2.getDeviceType()); + assertEquals("portrait", browser2.getDeviceOrientation()); + + Browser browser3 = browsers.get(2); + assertEquals("Linuxfirefox4", browser3.getKey()); + assertEquals("Linux", browser3.getOs()); + assertEquals("firefox", browser3.getBrowserName()); + assertEquals("4", browser3.getVersion()); + assertEquals("Linux Firefox 4", browser3.getName()); + assertEquals("4.0.1.", browser3.getLongVersion()); + assertEquals("Firefox", browser3.getLongName()); + assertNull(browser3.getDevice()); + assertNull(browser3.getDeviceType()); + assertNull(browser3.getDeviceOrientation()); + + Browser browser4 = browsers.get(3); + assertEquals("Linuxfirefoxlatest", browser4.getKey()); + assertEquals("Linux", browser4.getOs()); + assertEquals("firefox", browser4.getBrowserName()); + assertEquals("latest", browser4.getVersion()); + assertEquals("Linux Firefox latest", browser4.getName()); + assertEquals("latest", browser4.getLongVersion()); + assertEquals("Firefox", browser4.getLongName()); + assertNull(browser4.getDevice()); + assertNull(browser4.getDeviceType()); + assertNull(browser4.getDeviceOrientation()); } @Test - public void testDuplicateMobileDevice() { + void testDuplicateMobileDevice() { String obj = "{\"deprecated_backend_versions\": [\"1.4.13\"], \"short_version\": \"4.4\", \"long_name\": \"Amazon Kindle Fire HD 8.9 GoogleAPI Emulator\", \"recommended_backend_version\": \"1.5.3\", \"long_version\": \"4.4.\", \"api_name\": \"android\", \"supported_backend_versions\": [\"1.4.16\", \"1.5.1\", \"1.5.2\", \"1.5.3\"], \"device\": \"KindleFireHDGoogleAPI\", \"latest_stable_version\": \"\", \"automation_backend\": \"appium\", \"os\": \"Linux\"}"; @@ -191,40 +186,33 @@ public void testDuplicateMobileDevice() { assertEquals(2, browsers.size()); - int elm = 0; - assertEquals( - "Amazon_Kindle_Fire_HD_8_9_GoogleAPI_Emulatorlandscapeandroid4_4_", - browsers.get(elm).getKey()); - assertEquals("android", browsers.get(elm).getOs()); - assertEquals("android", browsers.get(elm).getBrowserName()); - assertEquals("4.4", browsers.get(elm).getVersion()); - assertEquals( - "Amazon Kindle Fire HD 8.9 GoogleAPI Emulator 4.4 (landscape)", - browsers.get(elm).getName()); - assertEquals("4.4.", browsers.get(elm).getLongVersion()); - assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browsers.get(elm).getLongName()); - assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals("landscape", browsers.get(elm).getDeviceOrientation()); - - elm = 1; - assertEquals( - "Amazon_Kindle_Fire_HD_8_9_GoogleAPI_Emulatorportraitandroid4_4_", - browsers.get(elm).getKey()); - assertEquals("android", browsers.get(elm).getOs()); - assertEquals("android", browsers.get(elm).getBrowserName()); - assertEquals("4.4", browsers.get(elm).getVersion()); - assertEquals( - "Amazon Kindle Fire HD 8.9 GoogleAPI Emulator 4.4 (portrait)", browsers.get(elm).getName()); - assertEquals("4.4.", browsers.get(elm).getLongVersion()); - assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browsers.get(elm).getLongName()); - assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browsers.get(elm).getDevice()); - assertEquals(null, browsers.get(elm).getDeviceType()); - assertEquals("portrait", browsers.get(elm).getDeviceOrientation()); + Browser browser1 = browsers.get(0); + assertEquals("Amazon_Kindle_Fire_HD_8_9_GoogleAPI_Emulatorlandscapeandroid4_4_", browser1.getKey()); + assertEquals("android", browser1.getOs()); + assertEquals("android", browser1.getBrowserName()); + assertEquals("4.4", browser1.getVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator 4.4 (landscape)", browser1.getName()); + assertEquals("4.4.", browser1.getLongVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browser1.getLongName()); + assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browser1.getDevice()); + assertNull(browser1.getDeviceType()); + assertEquals("landscape", browser1.getDeviceOrientation()); + + Browser browser2 = browsers.get(1); + assertEquals("Amazon_Kindle_Fire_HD_8_9_GoogleAPI_Emulatorportraitandroid4_4_", browser2.getKey()); + assertEquals("android", browser2.getOs()); + assertEquals("android", browser2.getBrowserName()); + assertEquals("4.4", browser2.getVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator 4.4 (portrait)", browser2.getName()); + assertEquals("4.4.", browser2.getLongVersion()); + assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browser2.getLongName()); + assertEquals("Amazon Kindle Fire HD 8.9 GoogleAPI Emulator", browser2.getDevice()); + assertNull(browser2.getDeviceType()); + assertEquals("portrait", browser2.getDeviceOrientation()); } @Test - public void testDuplicateWebDevice() { + void testDuplicateWebDevice() { String obj = "{\"short_version\": \"4\", \"long_name\": \"Firefox\", \"api_name\": \"firefox\", \"long_version\": \"4.0.1.\", \"latest_stable_version\": \"\", \"automation_backend\": \"webdriver\", \"os\": \"Linux\"}"; List browsers = @@ -233,28 +221,28 @@ public void testDuplicateWebDevice() { assertEquals(2, browsers.size()); - int elm = 0; - assertEquals("Linuxfirefox4", browsers.get(elm).getKey()); - assertEquals("Linux", browsers.get(elm).getOs()); - assertEquals("firefox", browsers.get(elm).getBrowserName()); - assertEquals("4", browsers.get(elm).getVersion()); - assertEquals("Linux Firefox 4", browsers.get(elm).getName()); - assertEquals("4.0.1.", browsers.get(elm).getLongVersion()); - assertEquals("Firefox", browsers.get(elm).getLongName()); - assertNull(browsers.get(elm).getDevice()); - assertNull(browsers.get(elm).getDeviceType()); - assertNull(browsers.get(elm).getDeviceOrientation()); - - elm = 1; - assertEquals("Linuxfirefoxlatest", browsers.get(elm).getKey()); - assertEquals("Linux", browsers.get(elm).getOs()); - assertEquals("firefox", browsers.get(elm).getBrowserName()); - assertEquals("latest", browsers.get(elm).getVersion()); - assertEquals("Linux Firefox latest", browsers.get(elm).getName()); - assertEquals("latest", browsers.get(elm).getLongVersion()); - assertEquals("Firefox", browsers.get(elm).getLongName()); - assertNull(browsers.get(elm).getDevice()); - assertNull(browsers.get(elm).getDeviceType()); - assertNull(browsers.get(elm).getDeviceOrientation()); + Browser browser1 = browsers.get(0); + assertEquals("Linuxfirefox4", browser1.getKey()); + assertEquals("Linux", browser1.getOs()); + assertEquals("firefox", browser1.getBrowserName()); + assertEquals("4", browser1.getVersion()); + assertEquals("Linux Firefox 4", browser1.getName()); + assertEquals("4.0.1.", browser1.getLongVersion()); + assertEquals("Firefox", browser1.getLongName()); + assertNull(browser1.getDevice()); + assertNull(browser1.getDeviceType()); + assertNull(browser1.getDeviceOrientation()); + + Browser browser2 = browsers.get(1); + assertEquals("Linuxfirefoxlatest", browser2.getKey()); + assertEquals("Linux", browser2.getOs()); + assertEquals("firefox", browser2.getBrowserName()); + assertEquals("latest", browser2.getVersion()); + assertEquals("Linux Firefox latest", browser2.getName()); + assertEquals("latest", browser2.getLongVersion()); + assertEquals("Firefox", browser2.getLongName()); + assertNull(browser2.getDevice()); + assertNull(browser2.getDeviceType()); + assertNull(browser2.getDeviceOrientation()); } } diff --git a/src/test/java/com/saucelabs/ci/BuildInformationTest.java b/src/test/java/com/saucelabs/ci/BuildInformationTest.java index 192b128b..d688207f 100644 --- a/src/test/java/com/saucelabs/ci/BuildInformationTest.java +++ b/src/test/java/com/saucelabs/ci/BuildInformationTest.java @@ -1,35 +1,38 @@ package com.saucelabs.ci; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.commons.io.IOUtils; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashMap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import java.nio.charset.StandardCharsets; +import java.util.Map; /** Created by gavinmogan on 2016-02-10. */ -public class BuildInformationTest { +class BuildInformationTest { private BuildInformation build; - private JSONObject jobs; - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { JSONObject obj = new JSONObject( - IOUtils.toString(getClass().getResourceAsStream("/build_info.json"), "UTF-8")); + IOUtils.toString(getClass().getResourceAsStream("/build_info.json"), StandardCharsets.UTF_8)); build = new BuildInformation("1234"); build.populateFromJson(obj); } @Test - public void testBuildId() { + void testBuildId() { assertEquals("1234", build.getBuildId()); } @Test - public void testStatus() { + void testStatus() { assertEquals("failed", build.getStatus()); build.clearChanges(); @@ -50,10 +53,10 @@ public void testStatus() { } @Test - public void testPopulateFromJson() { + void testPopulateFromJson() { assertEquals("test-name", build.getName()); - jobs = new JSONObject(); + JSONObject jobs = new JSONObject(); jobs.put("finished", 7); jobs.put("passed", 5); jobs.put("failed", 2); @@ -70,7 +73,7 @@ public void testPopulateFromJson() { json.put("name", (String) null); build = new BuildInformation("1234"); build.populateFromJson(json); - assertEquals(null, build.getName()); + assertNull(build.getName()); json.put("name", "Something"); build = new BuildInformation("1234"); @@ -81,7 +84,7 @@ public void testPopulateFromJson() { json.put("status", (String) null); build = new BuildInformation("1234"); build.populateFromJson(json); - assertEquals(null, build.getStatus()); + assertNull(build.getStatus()); json.put("status", "success"); build = new BuildInformation("1234"); @@ -127,10 +130,7 @@ public void testPopulateFromJson() { } @Test - public void testBuildName() { - HashMap updates = new HashMap<>(); - updates.put("name", "Gavin's first build"); - + void testBuildName() { assertEquals("test-name", build.getName()); assertFalse(build.hasChanges()); build.setName(null); @@ -142,19 +142,16 @@ public void testBuildName() { build.setName("Gavin's first build"); assertTrue(build.hasBuildName()); assertTrue(build.hasChanges()); - assertEquals(updates, build.getChanges()); + assertEquals(Map.of("name", "Gavin's first build"), build.getChanges()); } @Test - public void testGetChange() { - HashMap updates = new HashMap<>(); - updates.put("name", "name-name-name"); - + void testGetChange() { assertEquals("test-name", build.getName()); assertFalse(build.hasChanges()); build.setName("name-name-name"); assertTrue(build.hasChanges()); - assertEquals(updates, build.getChanges()); + assertEquals(Map.of("name", "name-name-name"), build.getChanges()); } /* TODO - figure out how to test equals */ diff --git a/src/test/java/com/saucelabs/ci/BuildJobInformationTest.java b/src/test/java/com/saucelabs/ci/BuildJobInformationTest.java index f008e160..e886a955 100644 --- a/src/test/java/com/saucelabs/ci/BuildJobInformationTest.java +++ b/src/test/java/com/saucelabs/ci/BuildJobInformationTest.java @@ -1,33 +1,34 @@ package com.saucelabs.ci; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.commons.io.IOUtils; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import java.nio.charset.StandardCharsets; import java.util.EnumSet; -import java.util.HashMap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import java.util.Map; -public class BuildJobInformationTest { +class BuildJobInformationTest { private BuildJobInformation job; - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { JSONObject obj = new JSONObject( - IOUtils.toString(getClass().getResourceAsStream("/build_job.json"), "UTF-8")); + IOUtils.toString(getClass().getResourceAsStream("/build_job.json"), StandardCharsets.UTF_8)); job = new BuildJobInformation(obj); } @Test - public void testBuildJobInformation_ConstructorFromJSON() throws Exception { + void testBuildJobInformation_ConstructorFromJSON() throws Exception { JSONObject obj = new JSONObject( - IOUtils.toString(getClass().getResourceAsStream("/build_job.json"), "UTF-8")); + IOUtils.toString(getClass().getResourceAsStream("/build_job.json"), StandardCharsets.UTF_8)); job = new BuildJobInformation(obj); assertEquals(1641976754, job.getCreationTime()); @@ -40,7 +41,7 @@ public void testBuildJobInformation_ConstructorFromJSON() throws Exception { } @Test - public void testBuildJobInformation_ConstructorFromId() { + void testBuildJobInformation_ConstructorFromId() { job = new BuildJobInformation("1234"); assertEquals("1234", job.getJobId()); @@ -51,33 +52,33 @@ public void testBuildJobInformation_ConstructorFromId() { } @Test - public void testJobId() { + void testJobId() { assertEquals("1375ba7db500432a97fbd0d99ce2bff2", job.getJobId()); } @Test - public void testSetGetCreationTime() { + void testSetGetCreationTime() { job.setCreationTime(25); assertEquals(25, job.getCreationTime()); } @Test - public void testSetGetModificationTime() { + void testSetGetModificationTime() { job.setModificationTime(26); assertEquals(26, job.getModificationTime()); } @Test - public void testSetGetDeletionTime() { + void testSetGetDeletionTime() { job.setDeletionTime(26); assertEquals(26, job.getDeletionTime()); } @Test - public void testSetStatusFlag() { + void testSetStatusFlag() { assertFalse(job.getStatus().contains(BuildJobInformation.JobStatusFlag.PUBLIC)); assertFalse(job.hasChanges()); @@ -88,7 +89,7 @@ public void testSetStatusFlag() { } @Test - public void testClearStatusFlag() { + void testClearStatusFlag() { job.setStatusFlag(BuildJobInformation.JobStatusFlag.PUBLIC); job.clearChanges(); assertTrue(job.getStatus().contains(BuildJobInformation.JobStatusFlag.PUBLIC)); @@ -101,7 +102,7 @@ public void testClearStatusFlag() { } @Test - public void testPopulateFromJson() { + void testPopulateFromJson() { JSONObject states = new JSONObject(); states.put("completed", true); states.put("errored", true); @@ -130,13 +131,10 @@ public void testPopulateFromJson() { } @Test - public void testGetChange() { - HashMap updates = new HashMap<>(); - updates.put("creationTime", (long) 1); - + void testGetChange() { assertFalse(job.hasChanges()); job.setCreationTime(1); assertTrue(job.hasChanges()); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("creationTime", (long) 1), job.getChanges()); } } diff --git a/src/test/java/com/saucelabs/ci/JobInformationTest.java b/src/test/java/com/saucelabs/ci/JobInformationTest.java index 0013f078..fdd1fd18 100644 --- a/src/test/java/com/saucelabs/ci/JobInformationTest.java +++ b/src/test/java/com/saucelabs/ci/JobInformationTest.java @@ -1,43 +1,44 @@ package com.saucelabs.ci; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.commons.io.IOUtils; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashMap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; +import java.util.Map; /** Created by gavinmogan on 2016-02-10. */ public class JobInformationTest { private JobInformation job; - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { JSONObject obj = - new JSONObject(IOUtils.toString(getClass().getResourceAsStream("/job_info.json"), "UTF-8")); + new JSONObject(IOUtils.toString(getClass().getResourceAsStream("/job_info.json"), StandardCharsets.UTF_8)); job = new JobInformation("1234", "hmac"); job.populateFromJson(obj); } @Test - public void testHMAC() { + void testHMAC() { assertEquals("hmac", job.getHmac()); job.setHmac("newhmac"); assertEquals("newhmac", job.getHmac()); } @Test - public void testJobId() { + void testJobId() { assertEquals("1234", job.getJobId()); } @Test - public void testStatus() { + void testStatus() { assertEquals("Passed", job.getStatus()); job.clearChanges(); @@ -56,7 +57,7 @@ public void testStatus() { } @Test - public void testPopulateFromJson() { + void testPopulateFromJson() { assertFalse(job.hasJobName()); assertNull(job.getName()); @@ -76,7 +77,7 @@ public void testPopulateFromJson() { json.put("name", (String) null); job = new JobInformation("1234", "hmac"); job.populateFromJson(json); - assertEquals(null, job.getName()); + assertNull(job.getName()); json.put("name", "Something"); job = new JobInformation("1234", "hmac"); @@ -87,7 +88,7 @@ public void testPopulateFromJson() { json.put("build", (String) null); job = new JobInformation("1234", "hmac"); job.populateFromJson(json); - assertEquals(null, job.getBuild()); + assertNull(job.getBuild()); json.put("build", "Something"); job = new JobInformation("1234", "hmac"); @@ -98,7 +99,7 @@ public void testPopulateFromJson() { json.put("passed", (String) null); job = new JobInformation("1234", "hmac"); job.populateFromJson(json); - assertEquals(null, job.getStatus()); + assertNull(job.getStatus()); json.put("passed", true); job = new JobInformation("1234", "hmac"); @@ -133,10 +134,7 @@ public void testPopulateFromJson() { } @Test - public void testFailureMessage() { - HashMap updates = new HashMap<>(); - updates.put("failureMessage", "test failure"); - + void testFailureMessage() { assertNull(job.getFailureMessage()); assertFalse(job.hasFailureMessage()); assertFalse(job.hasChanges()); @@ -149,14 +147,11 @@ public void testFailureMessage() { job.setFailureMessage("test failure"); assertTrue(job.hasFailureMessage()); assertTrue(job.hasChanges()); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("failureMessage", "test failure"), job.getChanges()); } @Test - public void testJobName() { - HashMap updates = new HashMap<>(); - updates.put("name", "Gavin's first job"); - + void testJobName() { assertFalse(job.hasJobName()); assertNull(job.getName()); assertFalse(job.hasChanges()); @@ -169,14 +164,11 @@ public void testJobName() { job.setName("Gavin's first job"); assertTrue(job.hasJobName()); assertTrue(job.hasChanges()); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("name", "Gavin's first job"), job.getChanges()); } @Test - public void testBuildName() { - HashMap updates = new HashMap<>(); - updates.put("build", "build-name"); - + void testBuildName() { assertFalse(job.hasBuild()); assertNull(job.getBuild()); assertFalse(job.hasChanges()); @@ -192,14 +184,11 @@ public void testBuildName() { assertTrue(job.hasChanges()); assertTrue(job.hasBuild()); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("build", "build-name"), job.getChanges()); } @Test - public void testBrowser() { - HashMap updates = new HashMap<>(); - updates.put("browser", "firefox"); - + void testBrowser() { assertEquals("iexplore", job.getBrowser()); assertFalse(job.hasChanges()); @@ -208,14 +197,11 @@ public void testBrowser() { assertEquals("firefox", job.getBrowser()); assertTrue(job.hasChange("browser")); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("browser", "firefox"), job.getChanges()); } @Test - public void testVersion() { - HashMap updates = new HashMap<>(); - updates.put("version", "20"); - + void testVersion() { assertEquals("10", job.getVersion()); assertFalse(job.hasChanges()); @@ -224,14 +210,11 @@ public void testVersion() { assertEquals("20", job.getVersion()); assertTrue(job.hasChange("version")); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("version", "20"), job.getChanges()); } @Test - public void testOs() { - HashMap updates = new HashMap<>(); - updates.put("os", "20"); - + void testOs() { assertEquals("Windows 7", job.getOs()); assertFalse(job.hasChanges()); @@ -241,7 +224,7 @@ public void testOs() { assertEquals("20", job.getOs()); assertTrue(job.hasChange("os")); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("os", "20"), job.getChanges()); /* Test mapped os */ job.setOs("Windows 2012 R2"); @@ -249,17 +232,12 @@ public void testOs() { assertEquals("Windows 8.1", job.getOs()); assertTrue(job.hasChange("os")); - updates.put("os", "Windows 2012 R2"); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("os", "Windows 2012 R2"), job.getChanges()); } @Test - public void testVideoUrl() { - HashMap updates = new HashMap<>(); - updates.put("videoUrl", "20"); - - assertEquals( - "https://saucelabs.com/jobs/449f8e8f5940483ea6938ce6cdbea117/video.flv", job.getVideoUrl()); + void testVideoUrl() { + assertEquals("https://saucelabs.com/jobs/449f8e8f5940483ea6938ce6cdbea117/video.flv", job.getVideoUrl()); assertFalse(job.hasChanges()); job.setVideoUrl("20"); @@ -267,14 +245,11 @@ public void testVideoUrl() { assertEquals("20", job.getVideoUrl()); assertTrue(job.hasChange("videoUrl")); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("videoUrl", "20"), job.getChanges()); } @Test - public void testLogUrl() { - HashMap updates = new HashMap<>(); - updates.put("logUrl", "20"); - + void testLogUrl() { assertEquals( "https://saucelabs.com/jobs/449f8e8f5940483ea6938ce6cdbea117/selenium-server.log", job.getLogUrl()); @@ -285,21 +260,17 @@ public void testLogUrl() { assertEquals("20", job.getLogUrl()); assertTrue(job.hasChange("logUrl")); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("logUrl", "20"), job.getChanges()); } @Test - public void testGetChange() { - HashMap updates = new HashMap<>(); - updates.put("build", "build-name"); - updates.put("name", "name-name-name"); - + void testGetChange() { assertNull(job.getName()); assertFalse(job.hasChanges()); job.setBuild("build-name"); job.setName("name-name-name"); assertTrue(job.hasChanges()); - assertEquals(updates, job.getChanges()); + assertEquals(Map.of("build", "build-name", "name", "name-name-name"), job.getChanges()); } /* TODO - figure out how to test equals */ diff --git a/src/test/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManagerTest.java b/src/test/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManagerTest.java index 7c88293d..8a7419a3 100644 --- a/src/test/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManagerTest.java +++ b/src/test/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManagerTest.java @@ -1,52 +1,52 @@ package com.saucelabs.ci.sauceconnect; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.concurrent.Semaphore; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import org.junit.jupiter.api.Test; /** Created by gavinmogan on 2016-07-13. */ -public class AbstractSauceTunnelManagerTest { +class AbstractSauceTunnelManagerTest { @Test - public void testGetTunnelName() { + void testGetTunnelName() { assertEquals( - "missing parameter", "default", - AbstractSauceTunnelManager.getTunnelName("basic -c", "default")); + AbstractSauceTunnelManager.getTunnelName("basic -c", "default"), + "missing parameter"); assertEquals( - "basic -i", "basic", AbstractSauceTunnelManager.getTunnelName("-i basic -c", "default")); + "basic", AbstractSauceTunnelManager.getTunnelName("-i basic -c", "default"), "basic -i"); assertEquals( - "basic --tunnel-name", "basic", - AbstractSauceTunnelManager.getTunnelName("--tunnel-name basic -c", "default")); + AbstractSauceTunnelManager.getTunnelName("--tunnel-name basic -c", "default"), + "basic --tunnel-name"); assertEquals( - "old --tunnel-identifier", "basic", - AbstractSauceTunnelManager.getTunnelName("--tunnel-identifier basic -c", "default")); + AbstractSauceTunnelManager.getTunnelName("--tunnel-identifier basic -c", "default"), + "old --tunnel-identifier"); assertEquals( - "mix of -i and --tunnel-name still returns the last one", "third", AbstractSauceTunnelManager.getTunnelName( - "-i first --tunnel-name second -c -i third", "default")); + "-i first --tunnel-name second -c -i third", "default"), + "mix of -i and --tunnel-name still returns the last one"); } @Test - public void testGetLogfile() { - assertNull("missing parameter", AbstractSauceTunnelManager.getLogfile("basic -c")); - assertEquals("basic -l", "basic", AbstractSauceTunnelManager.getLogfile("-l basic -c")); + void testGetLogfile() { + assertNull(AbstractSauceTunnelManager.getLogfile("basic -c"), "missing parameter"); + assertEquals("basic", AbstractSauceTunnelManager.getLogfile("-l basic -c"), "basic -l"); assertEquals( - "basic --logfile", "basic", AbstractSauceTunnelManager.getLogfile("--logfile basic -c")); + "basic", AbstractSauceTunnelManager.getLogfile("--logfile basic -c"), "basic --logfile"); assertEquals( - "mix of -l and --logfile still returns the last one", "third", - AbstractSauceTunnelManager.getLogfile("-l first --logfile second -c -l third")); + AbstractSauceTunnelManager.getLogfile("-l first --logfile second -c -l third"), + "mix of -l and --logfile still returns the last one"); } @Test - public void testSystemOutGobbler_ProcessLine() { + void testSystemOutGobbler_ProcessLine() { Semaphore semaphore = new Semaphore(1); SauceConnectFourManager man = new SauceConnectFourManager(true); AbstractSauceTunnelManager.SystemOutGobbler sot = man.makeOutputGobbler(null, null, semaphore); diff --git a/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectDidNotStartExceptionTest.java b/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectDidNotStartExceptionTest.java index a763aeff..831e3c80 100644 --- a/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectDidNotStartExceptionTest.java +++ b/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectDidNotStartExceptionTest.java @@ -1,13 +1,13 @@ package com.saucelabs.ci.sauceconnect; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -public class SauceConnectDidNotStartExceptionTest { +class SauceConnectDidNotStartExceptionTest { @Test - public void shouldPropagateConstructionParams() { + void shouldPropagateConstructionParams() { String message = "an error occurred " + System.currentTimeMillis(); assertEquals( message, diff --git a/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectFourManagerTest.java b/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectFourManagerTest.java index 165c0168..26ae4600 100755 --- a/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectFourManagerTest.java +++ b/src/test/java/com/saucelabs/ci/sauceconnect/SauceConnectFourManagerTest.java @@ -5,14 +5,16 @@ import com.saucelabs.saucerest.SauceREST; import com.saucelabs.saucerest.api.SauceConnectEndpoint; import com.saucelabs.saucerest.model.sauceconnect.TunnelInformation; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.ByteArrayInputStream; import java.io.File; @@ -20,20 +22,20 @@ import java.io.InputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.concurrent.TimeUnit; -import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class SauceConnectFourManagerTest { - - @Rule public TemporaryFolder folder = new TemporaryFolder(); +@ExtendWith(MockitoExtension.class) +class SauceConnectFourManagerTest { @Mock private Process mockProcess; @Mock private SauceREST mockSauceRest; @@ -42,9 +44,8 @@ public class SauceConnectFourManagerTest { private final PrintStream ps = System.out; - @Before - public void setup() { - MockitoAnnotations.initMocks(this); + @BeforeEach + void beforeEach() { when(mockSauceRest.getSauceConnectEndpoint()).thenReturn(mockSCEndpoint); tunnelManager.setSauceRest(mockSauceRest); } @@ -53,37 +54,27 @@ private InputStream getResourceAsStream(String resourceName) { return getClass().getResourceAsStream(resourceName); } - @Test - public void testOpenConnectionSuccessfullyWithoutCleanUpOnExit() throws IOException { - testOpenConnectionSuccessfully(false); - } - - @Test - public void testOpenConnectionSuccessfullyWithCleanUpOnExit() throws IOException { - testOpenConnectionSuccessfully(true); - } - - private void testOpenConnectionSuccessfully(boolean cleanUpOnExit) throws IOException { - List empty = new ArrayList(); - when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(empty); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testOpenConnectionSuccessfully(boolean cleanUpOnExit) throws IOException { + when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(List.of()); tunnelManager.setCleanUpOnExit(cleanUpOnExit); Process process = testOpenConnection("/started_sc.log"); assertEquals(mockProcess, process); } - @Test(expected = AbstractSauceTunnelManager.SauceConnectDidNotStartException.class) - public void openConnectionTest_closes() throws IOException, InterruptedException { - List empty = new ArrayList(); - when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(empty); + @Test + void openConnectionTest_closes() throws IOException, InterruptedException { + when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(List.of()); when(mockProcess.waitFor(30, TimeUnit.SECONDS)).thenReturn(true); - testOpenConnection("/started_sc_closes.log"); + assertThrows(AbstractSauceTunnelManager.SauceConnectDidNotStartException.class, () -> testOpenConnection( + "/started_sc_closes.log")); verify(mockProcess).destroy(); } @Test - public void testOpenConnectionWithExtraSpacesInArgs() throws IOException { - List empty = new ArrayList(); - when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(empty); + void testOpenConnectionWithExtraSpacesInArgs() throws IOException { + when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(List.of()); testOpenConnection("/started_sc.log", " username-with-spaces-around "); } @@ -126,41 +117,27 @@ private Process testOpenConnection(String logFile, String username) throws IOExc } @Test - public void openConnectionTest_existing_tunnel() throws IOException { - List active = new ArrayList<>(); - active.add("8949e55fb5e14fd6bf6230b7a609b494"); - + void openConnectionTest_existing_tunnel() throws IOException { TunnelInformation started = new TunnelInformation(); started.tunnelIdentifier = "8949e55fb5e14fd6bf6230b7a609b494"; started.status = "running"; - when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(active); - when(mockSCEndpoint.getTunnelInformation("8949e55fb5e14fd6bf6230b7a609b494")) - .thenReturn(started); - when(mockSauceRest.getSauceConnectEndpoint()).thenReturn(mockSCEndpoint); - tunnelManager.setSauceRest(mockSauceRest); + when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(List.of(started.tunnelIdentifier)); + when(mockSCEndpoint.getTunnelInformation(started.tunnelIdentifier)).thenReturn(started); Process process = testOpenConnection("/started_sc.log"); assertEquals(mockProcess, process); - verify(mockSCEndpoint).getTunnelInformation("8949e55fb5e14fd6bf6230b7a609b494"); + verify(mockSCEndpoint).getTunnelInformation(started.tunnelIdentifier); verify(mockSCEndpoint).getTunnelsForAUser(); } - @Test - public void testExtractZipFileWithoutCleanUpOnExit() throws IOException { - testExtractZipFile(false); - } - - @Test - public void testExtractZipFileWithCleanUpOnExit() throws IOException { - testExtractZipFile(true); - } - - private void testExtractZipFile(boolean cleanUpOnExit) throws IOException { - File linux_destination = folder.newFolder("sauceconnect_linux"); - File windows_destination = folder.newFolder("sauceconnect_windows"); - File osx_destination = folder.newFolder("sauceconnect_osx"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testExtractZipFile(boolean cleanUpOnExit, @TempDir Path folder) throws IOException { + File linux_destination = folder.resolve("sauceconnect_linux").toFile(); + File windows_destination = folder.resolve("sauceconnect_windows").toFile(); + File osx_destination = folder.resolve("sauceconnect_osx").toFile(); SauceConnectFourManager manager = new SauceConnectFourManager(); manager.setCleanUpOnExit(cleanUpOnExit); @@ -179,12 +156,13 @@ private void testExtractZipFile(boolean cleanUpOnExit) throws IOException { private void assertSauceConnectFileExists(String message, File destination, OperatingSystem os) { assertTrue( - message, - new File(new File(destination, os.getDirectory(false)), os.getExecutable()).exists()); + new File(new File(destination, os.getDirectory(false)), os.getExecutable()).exists(), + message + ); } @Test - public void testSauceConnectSecretsCoveredWithStars() { + void testSauceConnectSecretsCoveredWithStars() { SauceConnectFourManager manager = new SauceConnectFourManager(); String[] args = {"/sauce/connect/binary/path/"}; args = @@ -202,7 +180,7 @@ public void testSauceConnectSecretsCoveredWithStars() { } @Test - public void testSauceConnectSecretsWithSpecialCharactersCoveredWithStars() { + void testSauceConnectSecretsWithSpecialCharactersCoveredWithStars() { SauceConnectFourManager manager = new SauceConnectFourManager(); String[] args = {"-a", "web-proxy.domain.com:8080:user:pwd"}; assertEquals( diff --git a/src/test/java/com/saucelabs/sod/BrowserTest.java b/src/test/java/com/saucelabs/sod/BrowserTest.java index c5c71fd4..9edfd43b 100644 --- a/src/test/java/com/saucelabs/sod/BrowserTest.java +++ b/src/test/java/com/saucelabs/sod/BrowserTest.java @@ -6,30 +6,30 @@ import com.saucelabs.saucerest.api.PlatformEndpoint; import com.saucelabs.saucerest.model.platform.Platform; import com.saucelabs.saucerest.model.platform.SupportedPlatforms; -import org.junit.Test; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * @author Ross Rowe */ -public class BrowserTest { +class BrowserTest { private BrowserFactory browserFactory; - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { // Mock appium response - List appiumPlatforms = new ArrayList(); + List appiumPlatforms = new ArrayList<>(); Platform kindle = new Platform( @@ -96,17 +96,17 @@ public void setUp() throws Exception { } @Test - public void testNames() { + void testNames() { Browser browser = new Browser(null, null, null, null, null, null, "Windows 2008"); - assertEquals("windows 2008 is really windows 7", browser.getName(), "Windows 7"); + assertEquals(browser.getName(), "Windows 7", "windows 2008 is really windows 7"); browser = new Browser(null, null, null, null, null, null, "Windows 2003"); - assertEquals("windows 2003 is really windows xp", browser.getName(), "Windows XP"); + assertEquals(browser.getName(), "Windows XP", "windows 2003 is really windows xp"); } @Test - public void browserList() throws Exception { + void browserList() { - List appiumPlatforms = new ArrayList(); + List appiumPlatforms = new ArrayList<>(); Platform kindle = new Platform( @@ -125,19 +125,19 @@ public void browserList() throws Exception { appiumPlatforms.add(kindle); List browsers = browserFactory.getBrowserListFromPlatforms(appiumPlatforms); - assertFalse("browsers is empty", browsers.isEmpty()); + assertFalse(browsers.isEmpty(), "browsers is empty"); } @Test - public void browserFromSaucelabs() throws IOException { + void browserFromSaucelabs() throws IOException { List browsers = browserFactory.getWebDriverBrowsers(); - assertFalse("browsers is empty", browsers.isEmpty()); + assertFalse(browsers.isEmpty(), "browsers is empty"); browsers = browserFactory.getAppiumBrowsers(); - assertFalse("browsers is empty", browsers.isEmpty()); + assertFalse(browsers.isEmpty(), "browsers is empty"); } @Test - public void copyBrowser() { + void copyBrowser() { Browser orig = new Browser( "thisismykey", diff --git a/src/test/java/com/saucelabs/sod/ExtractFiles.java b/src/test/java/com/saucelabs/sod/ExtractFiles.java index 285de800..d3fb913a 100644 --- a/src/test/java/com/saucelabs/sod/ExtractFiles.java +++ b/src/test/java/com/saucelabs/sod/ExtractFiles.java @@ -1,26 +1,26 @@ package com.saucelabs.sod; import com.saucelabs.ci.sauceconnect.SauceConnectFourManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; /** * @author Ross Rowe */ -public class ExtractFiles { +class ExtractFiles { private SauceConnectFourManager manager = new SauceConnectFourManager(); @Test - public void linux() throws Exception { + void linux() throws Exception { File workingDirectory = new File(System.getProperty("java.io.tmpdir")); manager.extractZipFile(workingDirectory, SauceConnectFourManager.OperatingSystem.LINUX); } @Test - public void windows() throws Exception { + void windows() throws Exception { File workingDirectory = new File(System.getProperty("java.io.tmpdir")); manager.extractZipFile(workingDirectory, SauceConnectFourManager.OperatingSystem.WINDOWS); }