View Javadoc

    1   package org.apache.turbine.util;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *   http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21
    22  import static org.junit.Assert.assertEquals;
    23
    24  import org.apache.turbine.test.BaseTestCase;
    25  import org.junit.Test;
    26
    27  /**
    28   * Testing of the BrowserDetector class.
    29   *
    30   * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
    31   * @version $Id$
    32   */
    33  public class BrowserDetectorTest extends BaseTestCase
    34  {
    35
    36
    37      @Test public void testFirefox()
    38      {
    39          String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5";
    40          BrowserDetector bd = new BrowserDetector(userAgent);
    41          assertEquals("Firefox", bd.getBrowserName());
    42          assertEquals(1.5f, bd.getBrowserVersion(), 0.0f);
    43          assertEquals("Windows", bd.getBrowserPlatform());
    44      }
    45
    46      @Test public void testOpera()
    47      {
    48          String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02";
    49          BrowserDetector bd = new BrowserDetector(userAgent);
    50          assertEquals("Opera", bd.getBrowserName());
    51          assertEquals(8.02f, bd.getBrowserVersion(), 0.0f);
    52          assertEquals("Windows", bd.getBrowserPlatform());
    53
    54          userAgent = "Opera/7.51 (Windows NT 5.1; U) [en]";
    55          bd = new BrowserDetector(userAgent);
    56          assertEquals("Opera", bd.getBrowserName());
    57          assertEquals(7.51f, bd.getBrowserVersion(), 0.0f);
    58          assertEquals("Windows", bd.getBrowserPlatform());
    59      }
    60
    61      @Test public void testIE()
    62      {
    63          String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    64          BrowserDetector bd = new BrowserDetector(userAgent);
    65          assertEquals("IE", bd.getBrowserName());
    66          assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
    67          assertEquals("Windows", bd.getBrowserPlatform());
    68
    69          userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
    70          bd = new BrowserDetector(userAgent);
    71          assertEquals("IE", bd.getBrowserName());
    72          assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
    73          assertEquals("Windows", bd.getBrowserPlatform());
    74      }
    75  }