Skip to content

Commit

Permalink
A Platform family returns null from getFamily
Browse files Browse the repository at this point in the history
Adding additional tests to verify this is actually true.
  • Loading branch information
shs96c committed Aug 29, 2017
1 parent bd255ec commit f4a22f2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
21 changes: 14 additions & 7 deletions java/client/src/org/openqa/selenium/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum Platform {
WINDOWS("") {
@Override
public Platform family() {
return WINDOWS;
return null;
}
},

Expand Down Expand Up @@ -87,7 +87,7 @@ public Platform family() {
MAC("mac", "darwin", "macOS", "os x") {
@Override
public Platform family() {
return MAC;
return null;
}
},

Expand Down Expand Up @@ -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;
}
},

Expand All @@ -183,7 +183,7 @@ public Platform family() {

IOS("iOS") {
@Override
public Platform family() { return IOS; }
public Platform family() { return null; }
},

/**
Expand Down Expand Up @@ -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();

Expand Down
31 changes: 31 additions & 0 deletions java/client/test/org/openqa/selenium/PlatformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f4a22f2

Please sign in to comment.