View Javadoc

1   /*
2    * Copyright 2012 Oracle Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.fatwire.gst.foundation.mobile.mobiforge;
17  
18  import static org.junit.Assert.assertEquals;
19  
20  import org.junit.Test;
21  
22  import com.fatwire.gst.foundation.mobile.DeviceType;
23  import com.fatwire.gst.foundation.mobile.mobiforge.MobiForgeDeviceDetector;
24  
25  public class MobiForceDeviceDetectorTest {
26  
27  	@Test
28  	public void testDetectDeviceTypeString_iphone() {
29  		String ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3";
30  
31  		DeviceType type = new MobiForgeDeviceDetector().detectDeviceType(ua);
32  		assertEquals(DeviceType.MOBILE, type);
33  
34  	}
35  
36  	@Test
37  	public void testDetectDeviceTypeString_ipad() {
38  		String ua = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10";
39  
40  		DeviceType type = new MobiForgeDeviceDetector().detectDeviceType(ua);
41  		assertEquals(DeviceType.TABLET, type);
42  
43  	}
44  
45  	@Test
46  	public void testDetectDeviceTypeString_desktop() {
47  		String ua = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
48  
49  		DeviceType type = new MobiForgeDeviceDetector().detectDeviceType(ua);
50  		assertEquals(DeviceType.DESKTOP, type);
51  
52  	}
53  
54  }