Subversion Repository Public Repository

litesoft

Diff Revisions 943 vs 950 for /trunk/DeviceDesktopTest/src/org/litesoft/useragent/UserAgentFormFactorDeterminerImplTest.java

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