Skip to content

Commit

Permalink
assertj#25 remove check of mrj.version for identifying Macintosh OS.
Browse files Browse the repository at this point in the history
With Java 7 the system property mrj.version (which was used to identify
Mac OS in previous Java releases) doesn't return a non-null value on
Macs anymore.

Regarding to the note on
https://developer.apple.com/library/mac/technotes/tn2002/tn2110.html#MRJV
about the mrj.version, Macintoshs and Mac OS X are now identified by
checking if the system property os.name contains 'os x'.

This helps identifying Mac OS under Java 7 and following releases. But
it also removes support for identifying Mac OS 9. This shouldn't be
needed by anybody. But this commit should be changed if Mac OS 9 support
is needed!
  • Loading branch information
croesch authored and stefanmahler committed May 2, 2014
1 parent 5d3009b commit 8bd42d2
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class OSIdentifier {
private final boolean isWindows;
private final boolean isWindows9x;
private final boolean isWindowsXP;
private final boolean isMacintosh;
private final boolean isOSX;
private final boolean isX11;
private final boolean isSolaris;
Expand All @@ -49,12 +48,10 @@ class OSIdentifier {
@VisibleForTesting
OSIdentifier(@Nonnull SystemPropertyReader reader) {
String osName = checkNotNull(reader.systemProperty("os.name")).toLowerCase(ENGLISH);
String mrjVersion = reader.systemProperty("mrj.version");
isWindows = osName.startsWith("windows");
isWindows9x = isWindows && containsAny(osName, "95", "98", "me");
isWindowsXP = isWindows && osName.contains("xp");
isMacintosh = mrjVersion != null;
isOSX = isMacintosh && osName.contains("os x");
isOSX = osName.contains("os x");
isX11 = !isOSX && !isWindows;
isSolaris = osName.startsWith("sunos") || osName.startsWith("solaris");
isHPUX = osName.equals("hp-ux");
Expand Down Expand Up @@ -98,7 +95,8 @@ boolean isWindowsXP() {
}

boolean isMacintosh() {
return isMacintosh;
// currently we assume only Mac OS X is used
return isOSX();
}

boolean isOSX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,4 @@ public void setUp() {
final void returnOSName(String osName) {
when(propertyReader.systemProperty("os.name")).thenReturn(osName);
}

final void returnSomeMRJVersion() {
returnMRJVersion("6");
}

final void returnNoMRJVersion() {
returnMRJVersion(null);
}

final void returnMRJVersion(String mrjVersion) {
when(propertyReader.systemProperty("mrj.version")).thenReturn(mrjVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OSIdentifier_isHPUX_Test(String hpUX) {
@Test
public void should_return_HPUX_if_OS_name_is_equal_to_HPUX() {
returnOSName(hpUX);
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isHPUX()).isTrue();
assertThat(osIdentifier.isX11()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OSIdentifier_isLinux_Test(String linux) {
@Test
public void shouldReturnLinuxIfOSNameIsEqualToLinux() {
returnOSName(linux);
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isLinux()).isTrue();
assertThat(osIdentifier.isX11()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,47 @@
package org.assertj.swing.util;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Lists.newArrayList;
import static org.assertj.swing.util.OSFamily.MAC;

import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
* Tests for {@link OSIdentifier#isMacintosh()}.
*
* @author Alex Ruiz
*/
@RunWith(Parameterized.class)
public class OSIdentifier_isMacintosh_Test extends OSIdentifier_TestCase {
private final String osX;

@Parameters
public static Collection<Object[]> osX() {
return newArrayList(new Object[][] { { "os x" }, { "OS X" } });
}

public OSIdentifier_isMacintosh_Test(String osX) {
this.osX = osX;
}

@Test
public void should_return_Macintosh_if_MRJVersion_is_not_null() {
returnOSName("");
returnSomeMRJVersion();
public void should_return_OSX_if_OS_name_contains_OSX_even_if_mrj_version_is_Null() {
returnOSName(osX);
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isMacintosh()).isTrue();
assertThat(osIdentifier.isX11()).isTrue();
assertThat(osIdentifier.isOSX()).isTrue();
assertThat(osIdentifier.isHPUX()).isFalse();
assertThat(osIdentifier.isLinux()).isFalse();
assertThat(osIdentifier.isOSX()).isFalse();
assertThat(osIdentifier.isSolaris()).isFalse();
assertThat(osIdentifier.isWindows()).isFalse();
assertThat(osIdentifier.isWindows9x()).isFalse();
assertThat(osIdentifier.isWindowsXP()).isFalse();
assertThat(osIdentifier.isX11()).isFalse();
assertThat(osIdentifier.osFamily()).isEqualTo(MAC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OSIdentifier_isOSX_Test(String osX) {
@Test
public void should_return_OSX_if_MRJVersion_not_null_and_OS_name_contains_OSX() {
returnOSName(osX);
returnSomeMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isMacintosh()).isTrue();
assertThat(osIdentifier.isOSX()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public OSIdentifier_isSolaris_Test(String solaris) {
@Test
public void should_return_Solaris_if_OS_name_starts_with_SunOS_or_Solaris() {
returnOSName(solaris);
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isSolaris()).isTrue();
assertThat(osIdentifier.isX11()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OSIdentifier_isWindows9x_Test(String windows9x) {
@Test
public void should_return_is_Windows9x_if_OS_name_starts_with_Windows_and_contains_any_9x_version() {
returnOSName(windows9x);
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isWindows()).isTrue();
assertThat(osIdentifier.isWindows9x()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OSIdentifier_isWindowsXP_Test(String windowsXP) {
@Test
public void should_return_WindowsXP_if_OS_name_starts_with_Windows_and_contains_XP() {
returnOSName(windowsXP);
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isWindows()).isTrue();
assertThat(osIdentifier.isWindowsXP()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OSIdentifier_isWindows_Test(String windows) {
@Test
public void should_return_is_Windows_if_OS_name_starts_with_Windows() {
returnOSName(windows);
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isWindows()).isTrue();
assertThat(osIdentifier.isHPUX()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class OSIdentifier_isX11_Test extends OSIdentifier_TestCase {
@Test
public void should_return_X11_if_OS_not_OSX_or_Windows() {
returnOSName("");
returnNoMRJVersion();
OSIdentifier osIdentifier = new OSIdentifier(propertyReader);
assertThat(osIdentifier.isX11()).isTrue();
assertThat(osIdentifier.isHPUX()).isFalse();
Expand Down

0 comments on commit 8bd42d2

Please sign in to comment.