From e8dbb3175ef59aeaadcb959fe63d023e3371260d Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Tue, 12 Jan 2021 12:30:08 +0530 Subject: [PATCH] Add overloaded version of Require.positive for double --- .../org/openqa/selenium/internal/Require.java | 14 ++++++++++ .../selenium/printoptions/print/BUILD.bazel | 3 +++ .../printoptions/print/PageMargin.java | 26 +++++-------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/java/client/src/org/openqa/selenium/internal/Require.java b/java/client/src/org/openqa/selenium/internal/Require.java index 49a41782c3845f..ab581e4c9e39b4 100644 --- a/java/client/src/org/openqa/selenium/internal/Require.java +++ b/java/client/src/org/openqa/selenium/internal/Require.java @@ -159,6 +159,20 @@ public static int positive(String argName, Integer number, String message) { return number; } + public static double positive(String argName, Double number, String message) { + if (number == null) { + throw new IllegalArgumentException(String.format(ARG_MUST_BE_SET, argName)); + } + if (number <= 0) { + if (message == null) { + throw new IllegalArgumentException(argName + " must be greater than 0"); + } else { + throw new IllegalArgumentException(message); + } + } + return number; + } + public static int positive(String argName, Integer number) { return positive(argName, number, null); } diff --git a/java/client/src/org/openqa/selenium/printoptions/print/BUILD.bazel b/java/client/src/org/openqa/selenium/printoptions/print/BUILD.bazel index 698029c3400d33..8c813821503324 100644 --- a/java/client/src/org/openqa/selenium/printoptions/print/BUILD.bazel +++ b/java/client/src/org/openqa/selenium/printoptions/print/BUILD.bazel @@ -11,5 +11,8 @@ java_library( "//java/client/test/org/openqa/selenium/build:__pkg__", "//java/client/test/org/openqa/selenium/testing/drivers:__pkg__", "//java/client/src/org/openqa/selenium:__subpackages__", + ], + deps = [ + "//java/client/src/org/openqa/selenium:core", ] ) diff --git a/java/client/src/org/openqa/selenium/printoptions/print/PageMargin.java b/java/client/src/org/openqa/selenium/printoptions/print/PageMargin.java index a9a958b66eae0a..ef01d9017e6bb7 100644 --- a/java/client/src/org/openqa/selenium/printoptions/print/PageMargin.java +++ b/java/client/src/org/openqa/selenium/printoptions/print/PageMargin.java @@ -17,6 +17,8 @@ package org.openqa.selenium.printoptions.print; +import org.openqa.selenium.internal.Require; + public class PageMargin { private double top; private double bottom; @@ -47,34 +49,18 @@ public double getRight() { } public void setTop(double top) { - if (top < 0) { - throw new IllegalArgumentException("Top margin value should be > 0"); - } - - this.top = top; + this.top = Require.positive("top", top, null); } public void setBottom(double bottom) { - if (bottom < 0) { - throw new IllegalArgumentException("Bottom margin value should be > 0"); - } - - this.bottom = bottom; + this.bottom = Require.positive("bottom", bottom, null); } public void setRight(double right) { - if (right < 0) { - throw new IllegalArgumentException("Right margin value should be > 0"); - } - - this.right = right; + this.right = Require.positive("right", right, null); } public void setLeft(double left) { - if (left < 0) { - throw new IllegalArgumentException("Left margin value should be > 0"); - } - - this.left = left; + this.left = Require.positive("left", left, null); } }