/** Tests that Har resources are sorted properly by request time. */ @Test public void sortHarResources() throws Exception { HarResource a = EasyMock.createMock(HarResource.class); HarResource b = EasyMock.createMock(HarResource.class); HarResource c = EasyMock.createMock(HarResource.class); HarResource d = EasyMock.createMock(HarResource.class); EasyMock.expect(a.getRequestTime()).andReturn(new BigDecimal(1.328670831670000E9)).anyTimes(); EasyMock.expect(b.getRequestTime()).andReturn(new BigDecimal(1.328670831660000E9)).anyTimes(); EasyMock.expect(c.getRequestTime()).andReturn(new BigDecimal(1.328670831650000E9)).anyTimes(); EasyMock.expect(d.getRequestTime()).andReturn(null).anyTimes(); EasyMock.replay(a, b, c, d); HashMap<String, HarResource> map = Maps.newHashMap(); map.put("1.1", a); map.put("2.2", b); map.put("3.3", c); map.put("4.4", d); HarObject har = new HarObject(); List<Map.Entry<String, HarResource>> list = Lists.newArrayList(map.entrySet()); har.sortHarResources(list); String[] sortedRequestIds = {"4.4", "3.3", "2.2", "1.1"}; int i = 0; for (Map.Entry<String, HarResource> resource : list) { assertTrue(resource.getKey().equals(sortedRequestIds[i++])); } EasyMock.verify(a, b, c, d); }