-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Viet Nguyen Duc <[email protected]>
- Loading branch information
Showing
5 changed files
with
142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...aries/test-libraries-utilities/src/test/java/org/ndviet/library/math/MathHelpersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.ndviet.library.math; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.ndviet.library.configuration.ConfigurationHelpers; | ||
|
||
import java.util.Locale; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class MathHelpersTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideParametersForNumberDecimalFormat") | ||
public void numberDecimalFormat(String input, String decimal, String roundingMode, String expected) { | ||
String result = MathHelpers.numberDecimalFormat(input, decimal, roundingMode); | ||
assertEquals(expected, result); | ||
} | ||
|
||
private static Stream<Arguments> provideParametersForNumberDecimalFormat() { | ||
return Stream.of( | ||
Arguments.of("1234.5678", "#.##", "HALF_UP", "1234.57"), | ||
Arguments.of("invalid", "#.##", "HALF_UP", "invalid"), | ||
Arguments.of("1234.5678", "#.##", null, "1234.57"), | ||
Arguments.of("1234.5678", null, "HALF_UP", "1234.5678") | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"1234.5678, true", | ||
"0, true", | ||
"-1234, true", | ||
"1.23E3, true", | ||
"invalid, false", | ||
", false" | ||
}) | ||
public void isCreatable(String input, boolean expected) { | ||
assertEquals(expected, MathHelpers.isCreatable(input)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"'1234,5678', true", | ||
"'-0,75', true", | ||
}) | ||
public void isCreatable_different_locate(String input, boolean expected) { | ||
try (MockedStatic<ConfigurationHelpers> mockHelpers = Mockito.mockStatic(ConfigurationHelpers.class)) { | ||
mockHelpers.when(ConfigurationHelpers::getSystemLocale).thenReturn(Locale.FRANCE); | ||
assertEquals(expected, MathHelpers.isCreatable(input)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...braries/test-libraries-webui/src/test/java/org/ndviet/library/webui/driver/WebUITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.ndviet.library.webui.driver; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.ndviet.library.WebUI; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.ndviet.library.configuration.Constants.SELENIUM_BROWSER_TYPE; | ||
import static org.ndviet.library.configuration.Constants.SELENIUM_WEB_DRIVER_TARGET; | ||
|
||
public class WebUITest { | ||
|
||
@Mock | ||
private WebDriver mockDriver; | ||
|
||
@BeforeAll | ||
public static void setUpClass() { | ||
System.setProperty(SELENIUM_WEB_DRIVER_TARGET, "local"); | ||
System.setProperty(SELENIUM_BROWSER_TYPE, "chrome"); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
try (MockedStatic<TargetFactory> mockFactory = Mockito.mockStatic(TargetFactory.class)) { | ||
mockFactory.when(TargetFactory::createInstance).thenReturn(mockDriver); | ||
} | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
mockDriver.close(); | ||
} | ||
|
||
@Test | ||
public void openBrowser_returnsDriver() { | ||
mockDriver = WebUI.openBrowser(); | ||
assertNotNull(mockDriver); | ||
assertTrue(mockDriver instanceof ChromeDriver); | ||
} | ||
|
||
@Test | ||
public void openBrowser_withUrl_returnsDriver() { | ||
String url = "https://demoqa.com/"; | ||
mockDriver = WebUI.openBrowser(url); | ||
mockDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
assertNotNull(mockDriver); | ||
assertTrue(mockDriver.getTitle().equals("DEMOQA")); | ||
} | ||
} |