1818import org .apache .commons .collections .MapUtils ;
1919import org .apache .commons .collections .iterators .EmptyIterator ;
2020import org .apache .commons .collections .iterators .IteratorEnumeration ;
21- import org .apache .commons .lang .StringUtils ;
21+ import org .apache .commons .lang3 .JavaVersion ;
22+ import org .apache .commons .lang3 .StringUtils ;
23+ import org .apache .commons .lang3 .SystemUtils ;
2224import org .testng .Assert ;
2325import org .testng .annotations .BeforeClass ;
2426import org .testng .annotations .Test ;
@@ -50,6 +52,7 @@ public class WmClientTest {
5052
5153 @ BeforeClass
5254 public void createTestClient () throws WmException {
55+ System .out .println ("Running on Java version: " + SystemUtils .JAVA_VERSION );
5356 String host = "localhost" ;
5457 String port = "8080" ;
5558 String envHost = System .getenv ("WM_HOST" );
@@ -64,6 +67,12 @@ public void createTestClient() throws WmException {
6467
6568 }
6669
70+ @ Test
71+ public void javaVersionTest (){
72+ boolean isJava8min = SystemUtils .isJavaVersionAtLeast (JavaVersion .JAVA_1_8 );
73+ assertTrue (isJava8min , "Java 8 is the minimum version required to run WMClient and its tests" );
74+ }
75+
6776
6877 public WmClient createCachedTestClient (int csize ) throws WmException {
6978 String host = "localhost" ;
@@ -173,7 +182,6 @@ public void lookupUseragentEmptyUaTest() {
173182
174183 @ Test
175184 public void testLookupUseragentNullUa () {
176- boolean exc = false ;
177185 try {
178186 Model .JSONDeviceData device = _client .lookupUseragent (null );
179187 assertNotNull (device );
@@ -754,6 +762,7 @@ public void realCacheUsageTest() throws WmException {
754762
755763 @ Test
756764 public void realCacheUsageTest_2 () throws WmException {
765+
757766 String host = "localhost" ;
758767 String port = "8080" ;
759768 String envHost = System .getenv ("WM_HOST" );
@@ -765,13 +774,20 @@ public void realCacheUsageTest_2() throws WmException {
765774 port = envPort ;
766775 }
767776 WmClient client = WmClient .create ("http" , host , port , "" );
777+
778+ // We create a set of 10K elements
779+ List <String > testUserAgents = new ArrayList <>();
780+ for (int i =0 ; i <100 ;i ++){
781+ testUserAgents .addAll (Arrays .asList (TestData .USER_AGENTS ));
782+ }
783+
768784 try {
769785 long start = System .nanoTime ();
770- for (String ua : TestData . USER_AGENTS ){
786+ for (String ua : testUserAgents ){
771787 client .lookupUseragent (ua );
772788 }
773789 long elapsedNoCache = System .nanoTime () - start ;
774- double avgNoCache = (double )elapsedNoCache /(double )TestData . USER_AGENTS . length ;
790+ double avgNoCache = (double )elapsedNoCache /(double )testUserAgents . size () ;
775791
776792 // Now, let's add a cache layer
777793 client .setCacheSize (100000 );
@@ -783,14 +799,14 @@ public void realCacheUsageTest_2() throws WmException {
783799
784800 // now use it
785801 long nu_start = System .nanoTime ();
786- for (String ua : TestData . USER_AGENTS ){
802+ for (String ua : testUserAgents ){
787803 client .lookupUseragent (ua );
788804 }
789805 long elapsedWithCache = System .nanoTime () - nu_start ;
790- double avgWithCache = (double )elapsedWithCache /(double )TestData . USER_AGENTS . length ;
806+ double avgWithCache = (double )elapsedWithCache /(double )testUserAgents . size () ;
791807
792808 // Cache must be at least an order of magnitude faster
793- assertTrue (avgNoCache > avgWithCache * 10 );
809+ assertTrue (avgNoCache > avgWithCache * 100 );
794810
795811 }
796812 finally {
@@ -865,7 +881,7 @@ public WmClient createTestCachedClient(int csize) throws WmException {
865881 // Uses reflection to force invoke of private method clearCacheIfNeeded for testing purposes
866882 private void invokeClearCacheIfNeeded (WmClient client , String ltime ) throws ClassNotFoundException , NoSuchMethodException ,
867883 InvocationTargetException , IllegalAccessException {
868- Class clientClass = Class .forName ("com.scientiamobile.wurfl.wmclient.WmClient" );
884+ Class <?> clientClass = Class .forName ("com.scientiamobile.wurfl.wmclient.WmClient" );
869885 Method ms = clientClass .getDeclaredMethod ("clearCachesIfNeeded" , String .class );
870886 ms .setAccessible (true );
871887 ms .invoke (client , ltime );
@@ -876,9 +892,9 @@ private HttpServletRequest createTestRequest(final boolean provideHeaders) {
876892 return new HttpServletRequest () {
877893
878894 private final Map <String , String > headers = new HashMap <>();
879- private String ua = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341" ;
880- private String xucbr = "Mozilla/5.0 (Nintendo Switch; ShareApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341" ;
881- private String dstkUa = "Mozilla/5.0 (Nintendo Switch; WifiWebAuthApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341" ;
895+ private final String ua = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341" ;
896+ private final String xucbr = "Mozilla/5.0 (Nintendo Switch; ShareApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341" ;
897+ private final String dstkUa = "Mozilla/5.0 (Nintendo Switch; WifiWebAuthApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341" ;
882898
883899
884900 @ Override
0 commit comments