|
@@ -1,67 +1,79 @@ |
1 |
1 |
|
package org.litesoft.useragent; |
2 |
2 |
|
|
3 |
3 |
|
import junit.framework.Assert; |
4 |
|
- |
import org.junit.Test; |
|
4 |
+ |
import org.junit.*; |
5 |
5 |
|
|
6 |
|
- |
import java.io.File; |
7 |
|
- |
import java.io.IOException; |
8 |
|
- |
import java.util.ArrayList; |
9 |
|
- |
import java.util.List; |
10 |
|
- |
import java.util.Scanner; |
|
6 |
+ |
import java.io.*; |
|
7 |
+ |
import java.util.*; |
11 |
8 |
|
|
12 |
|
- |
public class UserAgentFormFactorDeterminerImplTest { |
|
9 |
+ |
public class UserAgentFormFactorDeterminerImplTest |
|
10 |
+ |
{ |
13 |
11 |
|
public static final String USER_AGENT_FILES_SUB_DIR = "UserAgentFiles"; |
14 |
12 |
|
|
15 |
13 |
|
private static final UserAgentFormFactorDeterminer FFD = new UserAgentFormFactorDeterminerImpl(); |
16 |
14 |
|
|
17 |
|
- |
private static String[] readTextFile(File pTextFile) throws IOException { |
|
15 |
+ |
private static String[] readTextFile( File pTextFile ) |
|
16 |
+ |
throws IOException |
|
17 |
+ |
{ |
18 |
18 |
|
List<String> zLines = new ArrayList<>(); |
19 |
|
- |
try (Scanner scanner = new Scanner(pTextFile, "UTF-8")) { |
20 |
|
- |
while (scanner.hasNextLine()) { |
21 |
|
- |
zLines.add(scanner.nextLine()); |
|
19 |
+ |
try (Scanner scanner = new Scanner( pTextFile, "UTF-8" )) |
|
20 |
+ |
{ |
|
21 |
+ |
while ( scanner.hasNextLine() ) |
|
22 |
+ |
{ |
|
23 |
+ |
zLines.add( scanner.nextLine() ); |
22 |
24 |
|
} |
23 |
25 |
|
} |
24 |
|
- |
return zLines.toArray(new String[zLines.size()]); |
|
26 |
+ |
return zLines.toArray( new String[zLines.size()] ); |
25 |
27 |
|
} |
26 |
28 |
|
|
27 |
|
- |
private static void checkFileEntries(UserAgentFormFactor pExpected, String pFileNameWithUserAgentPerLine) throws IOException { |
28 |
|
- |
String[] zLines = readTextFile(new File(USER_AGENT_FILES_SUB_DIR, pFileNameWithUserAgentPerLine + ".txt")); |
29 |
|
- |
for (int i = 0; i < zLines.length; i++) { |
|
29 |
+ |
private static void checkFileEntries( UserAgentFormFactor pExpected, String pFileNameWithUserAgentPerLine ) |
|
30 |
+ |
throws IOException |
|
31 |
+ |
{ |
|
32 |
+ |
String[] zLines = readTextFile( new File( USER_AGENT_FILES_SUB_DIR, pFileNameWithUserAgentPerLine + ".txt" ) ); |
|
33 |
+ |
for ( int i = 0; i < zLines.length; i++ ) |
|
34 |
+ |
{ |
30 |
35 |
|
String zLine = zLines[i].trim(); |
31 |
|
- |
if ((zLine.length() != 0) && !zLine.startsWith("!")) { |
32 |
|
- |
UserAgentFormFactor zActual = FFD.determine(zLine); |
33 |
|
- |
if (zActual != pExpected) { |
34 |
|
- |
Assert.assertEquals("From '" + pFileNameWithUserAgentPerLine + "[" + i + "]" + "': " + zLine, pExpected, zActual); |
|
36 |
+ |
if ( (zLine.length() != 0) && !zLine.startsWith( "!" ) ) |
|
37 |
+ |
{ |
|
38 |
+ |
UserAgentFormFactor zActual = FFD.determine( zLine ); |
|
39 |
+ |
if ( zActual != pExpected ) |
|
40 |
+ |
{ |
|
41 |
+ |
Assert.assertEquals( "From '" + pFileNameWithUserAgentPerLine + "[" + i + "]" + "': " + zLine, pExpected, zActual ); |
35 |
42 |
|
} |
36 |
43 |
|
} |
37 |
44 |
|
} |
38 |
45 |
|
} |
39 |
46 |
|
|
40 |
|
- |
private static void checkEntriesFromFiles(UserAgentFormFactor pExpected, String... pFileNamesWithUserAgentPerLine) throws IOException { |
41 |
|
- |
for (String zFileName : pFileNamesWithUserAgentPerLine) { |
42 |
|
- |
checkFileEntries(pExpected, zFileName); |
|
47 |
+ |
private static void checkEntriesFromFiles( UserAgentFormFactor pExpected, String... pFileNamesWithUserAgentPerLine ) |
|
48 |
+ |
throws IOException |
|
49 |
+ |
{ |
|
50 |
+ |
for ( String zFileName : pFileNamesWithUserAgentPerLine ) |
|
51 |
+ |
{ |
|
52 |
+ |
checkFileEntries( pExpected, zFileName ); |
43 |
53 |
|
} |
44 |
54 |
|
} |
45 |
55 |
|
|
46 |
56 |
|
@Test |
47 |
|
- |
public void testDetermine() throws Exception { |
48 |
|
- |
checkEntriesFromFiles(UserAgentFormFactor.SingleViewOnly, |
49 |
|
- |
"iPhone", |
50 |
|
- |
"iPod", |
51 |
|
- |
"iPad", |
52 |
|
- |
"Silk", |
53 |
|
- |
"Tizen", |
54 |
|
- |
"Kindle", |
55 |
|
- |
"Fennec", |
56 |
|
- |
"Android", |
57 |
|
- |
"IE-Mobile", |
58 |
|
- |
"SymbianOS", |
59 |
|
- |
"OperaMini", |
60 |
|
- |
"OperaMobi", |
61 |
|
- |
"OperaTablet", |
62 |
|
- |
"MobileFirefox"); |
|
57 |
+ |
public void testDetermine() |
|
58 |
+ |
throws Exception |
|
59 |
+ |
{ |
|
60 |
+ |
checkEntriesFromFiles( UserAgentFormFactor.SingleViewOnly, |
|
61 |
+ |
"iPhone", |
|
62 |
+ |
"iPod", |
|
63 |
+ |
"iPad", |
|
64 |
+ |
"Silk", |
|
65 |
+ |
"Tizen", |
|
66 |
+ |
"Kindle", |
|
67 |
+ |
"Fennec", |
|
68 |
+ |
"Android", |
|
69 |
+ |
"IE-Mobile", |
|
70 |
+ |
"SymbianOS", |
|
71 |
+ |
"OperaMini", |
|
72 |
+ |
"OperaMobi", |
|
73 |
+ |
"OperaTablet", |
|
74 |
+ |
"MobileFirefox" ); |
63 |
75 |
|
|
64 |
|
- |
checkEntriesFromFiles(UserAgentFormFactor.MultiViewable, |
65 |
|
- |
"Other"); |
|
76 |
+ |
checkEntriesFromFiles( UserAgentFormFactor.MultiViewable, |
|
77 |
+ |
"Other" ); |
66 |
78 |
|
} |
67 |
79 |
|
} |