|
| 1 | +package ru.chermenin.ua |
| 2 | + |
| 3 | +import org.junit.Test |
| 4 | +import kotlin.test.assertFalse |
| 5 | +import kotlin.test.assertTrue |
| 6 | + |
| 7 | +class CachedUserAgentParserTest { |
| 8 | + |
| 9 | + private val iPhoneString = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3" |
| 10 | + private val iPadString = "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10" |
| 11 | + private val galaxyTabString = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; SCH-I800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" |
| 12 | + private val galaxyS3String = "Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30" |
| 13 | + |
| 14 | + @Test |
| 15 | + fun testCachedParser() { |
| 16 | + val parser = CachedUserAgentParser(1, 3) |
| 17 | + |
| 18 | + val iPhone = parser.parse(iPhoneString) |
| 19 | + val iPad = parser.parse(iPadString) |
| 20 | + val galaxyTab = parser.parse(galaxyTabString) |
| 21 | + |
| 22 | + assertTrue("iPhone UA object must be the same") { iPhone === parser.parse(iPhoneString) } |
| 23 | + assertTrue("iPad UA object must be the same") { iPad === parser.parse(iPadString) } |
| 24 | + assertTrue("galaxyTab UA object must be the same") { galaxyTab === parser.parse(galaxyTabString) } |
| 25 | + |
| 26 | + val galaxyS3 = parser.parse(galaxyS3String) |
| 27 | + |
| 28 | + assertTrue("iPad UA object must be the same") { iPad === parser.parse(iPadString) } |
| 29 | + assertTrue("galaxyTab UA object must be the same") { galaxyTab === parser.parse(galaxyTabString) } |
| 30 | + assertTrue("galaxyS3 UA object must be the same") { galaxyS3 === parser.parse(galaxyS3String) } |
| 31 | + assertFalse("iPhone UA object already must not be the same") { iPhone === parser.parse(iPhoneString) } |
| 32 | + } |
| 33 | +} |
0 commit comments