From f4a22f2d6139482d4e878bfc0975f8b5d09c1dad Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Tue, 29 Aug 2017 12:29:22 +0100 Subject: [PATCH] A Platform family returns `null` from `getFamily` Adding additional tests to verify this is actually true. --- .../src/org/openqa/selenium/Platform.java | 21 ++++++++----- .../org/openqa/selenium/PlatformTest.java | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/java/client/src/org/openqa/selenium/Platform.java b/java/client/src/org/openqa/selenium/Platform.java index d8b8be09ce8fa..887bfe1c259c6 100644 --- a/java/client/src/org/openqa/selenium/Platform.java +++ b/java/client/src/org/openqa/selenium/Platform.java @@ -35,7 +35,7 @@ public enum Platform { WINDOWS("") { @Override public Platform family() { - return WINDOWS; + return null; } }, @@ -87,7 +87,7 @@ public Platform family() { MAC("mac", "darwin", "macOS", "os x") { @Override public Platform family() { - return MAC; + return null; } }, @@ -163,14 +163,14 @@ public String toString() { UNIX("solaris", "bsd") { @Override public Platform family() { - return UNIX; + return null; } }, LINUX("linux") { @Override public Platform family() { - return LINUX; + return UNIX; } }, @@ -183,7 +183,7 @@ public Platform family() { IOS("iOS") { @Override - public Platform family() { return IOS; } + public Platform family() { return null; } }, /** @@ -346,14 +346,21 @@ private static boolean isBetterMatch(String previous, String matcher) { * @return true if platforms are approximately similar, false otherwise */ public boolean is(Platform compareWith) { - return this == compareWith || this.family().is(compareWith); + return + // Any platform is itself + this == compareWith || + // Any platform is also ANY platform + compareWith == ANY || + // And any Platform which is not a platform type belongs to the same family + (this.family() != null && this.family().is(compareWith)); } /** * Returns a platform that represents a family for the current platform. For instance * the LINUX if a part of the UNIX family, the XP is a part of the WINDOWS family. * - * @return the family platform for the current one + * @return the family platform for the current one, or {@code null} if this {@code Platform} + * represents a platform family (such as Windows, or MacOS) */ public abstract Platform family(); diff --git a/java/client/test/org/openqa/selenium/PlatformTest.java b/java/client/test/org/openqa/selenium/PlatformTest.java index befd5db6586c5..95be47f7854c1 100644 --- a/java/client/test/org/openqa/selenium/PlatformTest.java +++ b/java/client/test/org/openqa/selenium/PlatformTest.java @@ -58,6 +58,11 @@ public void testUnixIsNotLinux() { assertFalse(Platform.UNIX.is(Platform.LINUX)); } + @Test + public void androidIsAUnixVariant() { + assertTrue(Platform.ANDROID.is(Platform.UNIX)); + } + @Test public void testXpIsAny() { assertTrue(Platform.XP.is(Platform.ANY)); @@ -73,6 +78,12 @@ public void testLinuxIsAny() { assertTrue(Platform.LINUX.is(Platform.ANY)); } + @Test + public void windowsIsNotMacOS() { + // Both of these are platform definitions, so return "null" for the family. + assertFalse(Platform.WINDOWS.is(Platform.MAC)); + } + @Test public void testUnixIsAny() { assertTrue(Platform.UNIX.is(Platform.ANY)); @@ -103,6 +114,26 @@ public void testShouldIdentifyLinux() { assertAllAre(Platform.LINUX, "Linux"); } + @Test + public void windowsIsWindows() { + assertTrue(Platform.WINDOWS.is(Platform.WINDOWS)); + } + + @Test + public void macIsMac() { + assertTrue(Platform.MAC.is(Platform.MAC)); + } + + @Test + public void linuxIsLinux() { + assertTrue(Platform.LINUX.is(Platform.LINUX)); + } + + @Test + public void unixIsUnix() { + assertTrue(Platform.UNIX.is(Platform.UNIX)); + } + @Test public void testWindows8Detection() { assertEquals("Windows NT with os version 6.2 should be detected as Windows 8",