public void testAddHeaders() { HttpRequestBase method = new HttpPost(); EasSyncService svc = new EasSyncService(); svc.mAuthString = "auth"; svc.mProtocolVersion = "12.1"; svc.mAccount = null; // With second argument false, there should be no header svc.setHeaders(method, false); Header[] headers = method.getHeaders("X-MS-PolicyKey"); assertEquals(0, headers.length); // With second argument true, there should always be a header // The value will be "0" without an account method.removeHeaders("X-MS-PolicyKey"); svc.setHeaders(method, true); headers = method.getHeaders("X-MS-PolicyKey"); assertEquals(1, headers.length); assertEquals("0", headers[0].getValue()); // With an account, but null security key, the header's value should be "0" Account account = new Account(); account.mSecuritySyncKey = null; svc.mAccount = account; method.removeHeaders("X-MS-PolicyKey"); svc.setHeaders(method, true); headers = method.getHeaders("X-MS-PolicyKey"); assertEquals(1, headers.length); assertEquals("0", headers[0].getValue()); // With an account and security key, the header's value should be the security key account.mSecuritySyncKey = "key"; svc.mAccount = account; method.removeHeaders("X-MS-PolicyKey"); svc.setHeaders(method, true); headers = method.getHeaders("X-MS-PolicyKey"); assertEquals(1, headers.length); assertEquals("key", headers[0].getValue()); }