コード例 #1
0
  @Test
  public void testArchitecture() {
    int foundArch = 0;

    // non-exhaustive list, covers conceivable architectures that might be running unit tests
    for (String arch : ARCHITECTURES) {
      if (matchArch(arch)) {
        foundArch++;
      }
    }

    assertEquals(
        foundArch,
        1,
        "Expected " + System.getProperty("os.arch") + " to be one of " + ARCHITECTURES);
  }
コード例 #2
0
public class OSCheckerTest {

  private static final String OS_NAME = System.getProperty("os.name");
  private static final List<String> ARCHITECTURES =
      Arrays.asList("i386", "i686", "x86", "x86_64", "amd64", "PowerPC", "ppc", "ppc64", "sparc");

  @Test
  public void testIsUnixOrWindows() {
    assertTrue(isUnix() || isWindows());
    assertFalse(isUnix() && isWindows());
  }

  @Test
  public void testLinuxVersionStringParsing() {

    String linuxVersionString = "2.6.32-279.14.1.el6.x86_64";
    parseVersion(linuxVersionString);
    assertEquals(getOsMajorVersion(), 2);
    assertEquals(getOsMinorVersion(), 6);
  }

  @Test
  public void testOSXVersionStringParsing() {
    String osXVersionString = "10.9.5";
    parseVersion(osXVersionString);
    assertEquals(getOsMajorVersion(), 10);
    assertEquals(getOsMinorVersion(), 9);
  }

  @Test
  public void testWindowsVersionStringParsing() {
    String windowsVersionString = "5.1";
    parseVersion(windowsVersionString);
    assertEquals(getOsMajorVersion(), 5);
    assertEquals(getOsMinorVersion(), 1);
  }

  @Test
  public void testNoMinorVersionStringParsing() {

    String noMinorString = "100";
    parseVersion(noMinorString);
    assertEquals(getOsMajorVersion(), 100);
    assertEquals(getOsMinorVersion(), 0);
  }

  @Test
  public void testInvalidVersionStringParsing() {

    // The exception output will end up in the TestCase debug log under the
    // target/test-cases directory as set in the POM.
    String exceptionString = "abc.10";
    parseVersion(exceptionString);
    assertEquals(getOsMajorVersion(), 0);
    assertEquals(getOsMinorVersion(), 0);
  }

  @Test
  public void testAtLeast() {
    parseVersion("1.2.3");
    assertTrue(atleast(OS_NAME, 1, 0));
    assertTrue(atleast(OS_NAME, 1, 2));
    assertFalse(atleast(OS_NAME, 1, 3));
    assertFalse(atleast(OS_NAME, 2, 1));
    assertFalse(atleast("iOS", 1, 0));
  }

  @Test
  public void testArchitecture() {
    int foundArch = 0;

    // non-exhaustive list, covers conceivable architectures that might be running unit tests
    for (String arch : ARCHITECTURES) {
      if (matchArch(arch)) {
        foundArch++;
      }
    }

    assertEquals(
        foundArch,
        1,
        "Expected " + System.getProperty("os.arch") + " to be one of " + ARCHITECTURES);
  }
}