This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d1c494  Add isWeb() to tell if the client is Hop Web
     new 0303afe  Merge pull request #416 from HiromuHota/HOP-13
9d1c494 is described below

commit 9d1c494d7bd21326a494bbfb6fc7f11168c6c6a3
Author: Hiromu Hota <[email protected]>
AuthorDate: Thu Nov 26 20:52:15 2020 -0800

    Add isWeb() to tell if the client is Hop Web
---
 .../java/org/apache/hop/ui/util/EnvironmentUtils.java   |  8 ++++++++
 .../org/apache/hop/ui/util/EnvironmentUtilsTest.java    | 17 +++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/ui/src/main/java/org/apache/hop/ui/util/EnvironmentUtils.java 
b/ui/src/main/java/org/apache/hop/ui/util/EnvironmentUtils.java
index a4987f4..15f4215 100644
--- a/ui/src/main/java/org/apache/hop/ui/util/EnvironmentUtils.java
+++ b/ui/src/main/java/org/apache/hop/ui/util/EnvironmentUtils.java
@@ -199,4 +199,12 @@ public class EnvironmentUtils {
     return "";
   }
 
+  /**
+   * Ask if the client is Hop Web.
+   * @return 'true' if Hop Web 'false' otherwise.
+   */
+  public boolean isWeb() {
+    return SWT.getPlatform().equals( "rap" );
+  }
+
 }
diff --git a/ui/src/test/java/org/apache/hop/ui/util/EnvironmentUtilsTest.java 
b/ui/src/test/java/org/apache/hop/ui/util/EnvironmentUtilsTest.java
index 9f5d595..ffe4c20 100644
--- a/ui/src/test/java/org/apache/hop/ui/util/EnvironmentUtilsTest.java
+++ b/ui/src/test/java/org/apache/hop/ui/util/EnvironmentUtilsTest.java
@@ -22,9 +22,14 @@
 
 package org.apache.hop.ui.util;
 
+import org.eclipse.swt.SWT;
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -33,6 +38,8 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.when;
 
+@RunWith( PowerMockRunner.class )
+@PrepareForTest( SWT.class )
 public class EnvironmentUtilsTest {
 
   @Test
@@ -79,6 +86,16 @@ public class EnvironmentUtilsTest {
     Assert.assertEquals( mock.getMockedInstance().getBrowserName(), "MSIE" );
   }
 
+  @Test
+  public void isWeb() {
+    // This should be true as long as the test runs on SWT.
+    assertFalse( EnvironmentUtils.getInstance().isWeb() );
+
+    PowerMockito.mockStatic( SWT.class );
+    when( SWT.getPlatform() ).thenReturn( "rap" );
+    assertTrue( EnvironmentUtils.getInstance().isWeb() );
+  }
+
   class EnvironmentUtilsMock extends EnvironmentUtils {
 
     private Case option;

Reply via email to