Skip to content

Commit f4a22f2

Browse files
committed
A Platform family returns null from getFamily
Adding additional tests to verify this is actually true.
1 parent bd255ec commit f4a22f2

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

java/client/src/org/openqa/selenium/Platform.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public enum Platform {
3535
WINDOWS("") {
3636
@Override
3737
public Platform family() {
38-
return WINDOWS;
38+
return null;
3939
}
4040
},
4141

@@ -87,7 +87,7 @@ public Platform family() {
8787
MAC("mac", "darwin", "macOS", "os x") {
8888
@Override
8989
public Platform family() {
90-
return MAC;
90+
return null;
9191
}
9292
},
9393

@@ -163,14 +163,14 @@ public String toString() {
163163
UNIX("solaris", "bsd") {
164164
@Override
165165
public Platform family() {
166-
return UNIX;
166+
return null;
167167
}
168168
},
169169

170170
LINUX("linux") {
171171
@Override
172172
public Platform family() {
173-
return LINUX;
173+
return UNIX;
174174
}
175175
},
176176

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

184184
IOS("iOS") {
185185
@Override
186-
public Platform family() { return IOS; }
186+
public Platform family() { return null; }
187187
},
188188

189189
/**
@@ -346,14 +346,21 @@ private static boolean isBetterMatch(String previous, String matcher) {
346346
* @return true if platforms are approximately similar, false otherwise
347347
*/
348348
public boolean is(Platform compareWith) {
349-
return this == compareWith || this.family().is(compareWith);
349+
return
350+
// Any platform is itself
351+
this == compareWith ||
352+
// Any platform is also ANY platform
353+
compareWith == ANY ||
354+
// And any Platform which is not a platform type belongs to the same family
355+
(this.family() != null && this.family().is(compareWith));
350356
}
351357

352358
/**
353359
* Returns a platform that represents a family for the current platform. For instance
354360
* the LINUX if a part of the UNIX family, the XP is a part of the WINDOWS family.
355361
*
356-
* @return the family platform for the current one
362+
* @return the family platform for the current one, or {@code null} if this {@code Platform}
363+
* represents a platform family (such as Windows, or MacOS)
357364
*/
358365
public abstract Platform family();
359366

java/client/test/org/openqa/selenium/PlatformTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public void testUnixIsNotLinux() {
5858
assertFalse(Platform.UNIX.is(Platform.LINUX));
5959
}
6060

61+
@Test
62+
public void androidIsAUnixVariant() {
63+
assertTrue(Platform.ANDROID.is(Platform.UNIX));
64+
}
65+
6166
@Test
6267
public void testXpIsAny() {
6368
assertTrue(Platform.XP.is(Platform.ANY));
@@ -73,6 +78,12 @@ public void testLinuxIsAny() {
7378
assertTrue(Platform.LINUX.is(Platform.ANY));
7479
}
7580

81+
@Test
82+
public void windowsIsNotMacOS() {
83+
// Both of these are platform definitions, so return "null" for the family.
84+
assertFalse(Platform.WINDOWS.is(Platform.MAC));
85+
}
86+
7687
@Test
7788
public void testUnixIsAny() {
7889
assertTrue(Platform.UNIX.is(Platform.ANY));
@@ -103,6 +114,26 @@ public void testShouldIdentifyLinux() {
103114
assertAllAre(Platform.LINUX, "Linux");
104115
}
105116

117+
@Test
118+
public void windowsIsWindows() {
119+
assertTrue(Platform.WINDOWS.is(Platform.WINDOWS));
120+
}
121+
122+
@Test
123+
public void macIsMac() {
124+
assertTrue(Platform.MAC.is(Platform.MAC));
125+
}
126+
127+
@Test
128+
public void linuxIsLinux() {
129+
assertTrue(Platform.LINUX.is(Platform.LINUX));
130+
}
131+
132+
@Test
133+
public void unixIsUnix() {
134+
assertTrue(Platform.UNIX.is(Platform.UNIX));
135+
}
136+
106137
@Test
107138
public void testWindows8Detection() {
108139
assertEquals("Windows NT with os version 6.2 should be detected as Windows 8",

0 commit comments

Comments
 (0)