Skip to content

Commit ff7d2e9

Browse files
Merge pull request #17 from WURFL/WPC-244
WPC-244: Fixed test. Test class code cleanup.
2 parents 5a53431 + afdcc2d commit ff7d2e9

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

wmclient/src/test/java/com/scientiamobile/wurfl/wmclient/WmClientTest.java

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import javax.servlet.http.HttpServletRequest;
3030
import javax.servlet.http.HttpSession;
3131
import java.io.*;
32-
import java.lang.reflect.Field;
3332
import java.lang.reflect.InvocationTargetException;
3433
import java.lang.reflect.Method;
3534
import java.security.Principal;
@@ -160,7 +159,7 @@ public void lookupUserAgentWithSpecificCapsTest() throws WmException {
160159
}
161160

162161
@Test
163-
public void lookupUseragentEmptyUaTest() throws WmException {
162+
public void lookupUseragentEmptyUaTest() {
164163

165164
boolean exc = false;
166165
try {
@@ -269,8 +268,8 @@ public void LookupRequestOKTest() throws WmException {
269268

270269
@Test
271270
public void LookupHeadersOKTest() throws WmException {
272-
HttpServletRequest request = createTestRequest(true);
273-
Map<String, String> headers = new HashMap<String, String>();
271+
272+
Map<String, String> headers = new HashMap<>();
274273
headers.put("User-Agent".toLowerCase(), "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341");
275274
headers.put("Content-Type".toLowerCase(), "gzip, deflate");
276275
headers.put("Accept-Encoding".toLowerCase(), "application/json");
@@ -294,7 +293,7 @@ public void LookupHeadersOKTest() throws WmException {
294293
@Test
295294
public void LookupHeadersWithMixedCaseTest() throws WmException {
296295
HttpServletRequest request = createTestRequest(true);
297-
Map<String, String> headers = new HashMap<String, String>();
296+
Map<String, String> headers = new HashMap<>();
298297
headers.put("User-AGenT", "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341");
299298
headers.put("Content-TYPe", "gzip, deflate");
300299
headers.put("Accept-EnCoding", "application/json");
@@ -319,7 +318,7 @@ public void LookupHeadersWithMixedCaseTest() throws WmException {
319318
public void LookupHeadersWithMixedCaseAndCachedClientTest() throws WmException {
320319
WmClient cachedClient = createTestCachedClient(1000);
321320
HttpServletRequest request = createTestRequest(true);
322-
Map<String, String> headers = new HashMap<String, String>();
321+
Map<String, String> headers = new HashMap<>();
323322
headers.put("User-AGenT", "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341");
324323
headers.put("Content-TYPe", "gzip, deflate");
325324
headers.put("Accept-EnCoding", "application/json");
@@ -343,7 +342,7 @@ public void LookupHeadersWithMixedCaseAndCachedClientTest() throws WmException {
343342
assertEquals(cacheSize[1], 1);
344343

345344
// Now mix headers case in a different way (we should hit the cache now)
346-
headers = new HashMap<String, String>();
345+
headers = new HashMap<>();
347346
headers.put("UseR-AGenT", "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341");
348347
headers.put("ConTent-TYPe", "gzip, deflate");
349348
headers.put("AccEpt-EnCoding", "application/json");
@@ -372,7 +371,7 @@ public void lookupHeadersWithNullOrEmptyHeadersTest() throws WmException {
372371
assertNotNull(capabilities);
373372
assertEquals("generic", capabilities.get("wurfl_id"));
374373

375-
device = _client.lookupHeaders(new HashMap<String, String>());
374+
device = _client.lookupHeaders(new HashMap<>());
376375
assertNotNull(device);
377376
capabilities = device.capabilities;
378377
assertNotNull(capabilities);
@@ -566,7 +565,7 @@ public void getAllDeviceMakesTest() throws Exception {
566565
// Testing a version before 1.2.0.0
567566
String v = client.getInfo().getWmVersion();
568567
if(VersionUtils.compareVersionNumbers(v, "1.2.0.0") < 0){
569-
System.out.println(String.format("Version is %s , skipping test", v));
568+
System.out.printf("Version is %s , skipping test%n", v);
570569
return;
571570
}
572571

@@ -585,7 +584,7 @@ public void getAllDevicesForMakeWithWrongMakeTest() throws Exception {
585584
// Testing a version before 1.2.0.0
586585
String v = client.getInfo().getWmVersion();
587586
if(VersionUtils.compareVersionNumbers(v, "1.2.0.0") < 0){
588-
System.out.println(String.format("Version is %s , skipping test", v));
587+
System.out.printf("Version is %s , skipping test%n", v);
589588
return;
590589
}
591590
try {
@@ -605,7 +604,7 @@ public void getAllDevicesForMakeTest() throws Exception {
605604

606605
String v = client.getInfo().getWmVersion();
607606
if(VersionUtils.compareVersionNumbers(v, "1.2.0.0") < 0){
608-
System.out.println(String.format("Version is %s , skipping test", v));
607+
System.out.printf("Version is %s , skipping test%n", v);
609608
return;
610609
}
611610

@@ -631,7 +630,7 @@ public void getAllOsesTest() throws Exception {
631630
try {
632631
String v = client.getInfo().getWmVersion();
633632
if(VersionUtils.compareVersionNumbers(v, "1.2.0.0") < 0){
634-
System.out.println(String.format("Version is %s , skipping test", v));
633+
System.out.printf("Version is %s , skipping test%n", v);
635634
return;
636635
}
637636

@@ -651,7 +650,7 @@ public void getAllVersionsForOSTest() throws Exception {
651650
try {
652651
String v = client.getInfo().getWmVersion();
653652
if(VersionUtils.compareVersionNumbers(v, "1.2.0.0") < 0){
654-
System.out.println(String.format("Version is %s , skipping test", v));
653+
System.out.printf("Version is %s , skipping test%n", v);
655654
return;
656655
}
657656

@@ -672,10 +671,10 @@ public void getAllVersionsForOsWithWrongOsTest() throws Exception {
672671
try {
673672
String v = client.getInfo().getWmVersion();
674673
if(VersionUtils.compareVersionNumbers(v, "1.2.0.0") < 0){
675-
System.out.println(String.format("Version is %s , skipping test", v));
674+
System.out.printf("Version is %s , skipping test%n", v);
676675
return;
677676
}
678-
client.getAllDevicesForMake("Fakething");
677+
client.getAllVersionsForOS("FakeOS");
679678
} finally {
680679
client.destroyConnection();
681680
}
@@ -775,27 +774,24 @@ public void realCacheUsageTest_2() throws WmException {
775774

776775
static List<Callable<Boolean>> createLookupTasks(int numTasks, final WmClient client) {
777776
final Map<String,String> testData = createExpectedValueMap(client);
778-
List<Callable<Boolean>> ltasks = new ArrayList<Callable<Boolean>>(numTasks);
777+
List<Callable<Boolean>> ltasks = new ArrayList<>(numTasks);
779778
for (int i = 0; i < numTasks; i++) {
780779
final int tindex = i;
781-
ltasks.add(new Callable<Boolean>() {
782-
@Override
783-
public Boolean call() throws Exception {
784-
System.out.println("Starting task#: " + tindex);
785-
int c = 0;
786-
try {
787-
for (String line: testData.keySet()) {
788-
Model.JSONDeviceData d = client.lookupUseragent(line);
789-
assertNotNull(d);
790-
assertEquals(d.capabilities.get("wurfl_id"), testData.get(line));
791-
c++;
792-
}
793-
System.out.println("Lines read from terminated task #" + tindex + ": " + c);
794-
return true;
795-
} catch (Exception e) {
796-
e.printStackTrace();
797-
return false;
780+
ltasks.add(() -> {
781+
System.out.println("Starting task#: " + tindex);
782+
int c = 0;
783+
try {
784+
for (String line: testData.keySet()) {
785+
Model.JSONDeviceData d = client.lookupUseragent(line);
786+
assertNotNull(d);
787+
assertEquals(d.capabilities.get("wurfl_id"), testData.get(line));
788+
c++;
798789
}
790+
System.out.println("Lines read from terminated task #" + tindex + ": " + c);
791+
return true;
792+
} catch (Exception e) {
793+
e.printStackTrace();
794+
return false;
799795
}
800796
});
801797
}
@@ -833,7 +829,7 @@ private void invokeClearCacheIfNeeded(WmClient client, String ltime) throws Clas
833829
private HttpServletRequest createTestRequest(final boolean provideHeaders) {
834830
return new HttpServletRequest() {
835831

836-
private Map<String, String> headers = new HashMap<String, String>();
832+
private Map<String, String> headers = new HashMap<>();
837833
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";
838834
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";
839835
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";
@@ -1012,7 +1008,7 @@ public String getContentType() {
10121008
}
10131009

10141010
@Override
1015-
public ServletInputStream getInputStream() throws IOException {
1011+
public ServletInputStream getInputStream() {
10161012
return null;
10171013
}
10181014

@@ -1057,7 +1053,7 @@ public int getServerPort() {
10571053
}
10581054

10591055
@Override
1060-
public BufferedReader getReader() throws IOException {
1056+
public BufferedReader getReader() {
10611057
return null;
10621058
}
10631059

@@ -1130,7 +1126,7 @@ public int getLocalPort() {
11301126

11311127
private static Map<String,String> createExpectedValueMap(WmClient client){
11321128
String[] userAgentList = TestData.createTestUserAgentList();
1133-
Map<String,String> m = new HashMap<String, String>();
1129+
Map<String,String> m = new HashMap<>();
11341130
for(String ua: userAgentList){
11351131
try {
11361132
m.put(ua, client.lookupUseragent(ua).capabilities.get("wurfl_id"));

0 commit comments

Comments
 (0)