Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.litesoft.useragent;

import org.junit.Test;

import junit.framework.Assert;

import java.io.*;
import java.util.*;

public class UserAgentFormFactorDeterminerImplTest {
    public static final String USER_AGENT_FILES_SUB_DIR = "UserAgentFiles";

    private static final UserAgentFormFactorDeterminer FFD = new UserAgentFormFactorDeterminerImpl();

    private static String[] readTextFile( File pTextFile )
            throws IOException {
        List<String> zLines = new ArrayList<>();
        try (Scanner scanner = new Scanner( pTextFile, "UTF-8" )) {
            while ( scanner.hasNextLine() ) {
                zLines.add( scanner.nextLine() );
            }
        }
        return zLines.toArray( new String[zLines.size()] );
    }

    private static void checkFileEntries( UserAgentFormFactor pExpected, String pFileNameWithUserAgentPerLine )
            throws IOException {
        String[] zLines = readTextFile( new File( USER_AGENT_FILES_SUB_DIR, pFileNameWithUserAgentPerLine + ".txt" ) );
        for ( int i = 0; i < zLines.length; i++ ) {
            String zLine = zLines[i].trim();
            if ( (zLine.length() != 0) && !zLine.startsWith( "!" ) ) {
                UserAgentFormFactor zActual = FFD.determine( zLine );
                if ( zActual != pExpected ) {
                    Assert.assertEquals( "From '" + pFileNameWithUserAgentPerLine + "[" + i + "]" + "': " + zLine, pExpected, zActual );
                }
            }
        }
    }

    private static void checkEntriesFromFiles( UserAgentFormFactor pExpected, String... pFileNamesWithUserAgentPerLine )
            throws IOException {
        for ( String zFileName : pFileNamesWithUserAgentPerLine ) {
            checkFileEntries( pExpected, zFileName );
        }
    }

    @Test
    public void testDetermine()
            throws Exception {
        checkEntriesFromFiles( UserAgentFormFactor.SingleViewOnly,
                               "iPhone",
                               "iPod",
                               "iPad",
                               "Silk",
                               "Tizen",
                               "Kindle",
                               "Fennec",
                               "Android",
                               "IE-Mobile",
                               "SymbianOS",
                               "OperaMini",
                               "OperaMobi",
                               "OperaTablet",
                               "MobileFirefox" );

        checkEntriesFromFiles( UserAgentFormFactor.MultiViewable,
                               "Other" );
    }
}

Commits for litesoft/trunk/DeviceDesktopTest/src/org/litesoft/useragent/UserAgentFormFactorDeterminerImplTest.java

Diff revisions: vs.
Revision Author Commited Message
961 Diff Diff GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:13:31 +0000

Externalization Work.

950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

943 Diff Diff GeorgeS picture GeorgeS Tue 03 Jun, 2014 04:25:50 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

926 Diff Diff GeorgeS picture GeorgeS Fri 14 Mar, 2014 23:58:15 +0000

Switched from Cookie to Param.

924 Diff Diff GeorgeS picture GeorgeS Fri 14 Mar, 2014 22:02:56 +0000

Drop IWS

920 GeorgeS picture GeorgeS Sun 16 Feb, 2014 19:06:51 +0000

DDT w/ Jetty