### Question:
AuthScope { public int match(final AuthScope that) { int factor = 0; if (LangUtils.equals(toNullSafeLowerCase(this.schemeName), toNullSafeLowerCase(that.schemeName))) { factor += 1; } else { if (this.schemeName != null && that.schemeName != null) { return -1; } } if (LangUtils.equals(this.realm, that.realm)) { factor += 2; } else { if (this.realm != null && that.realm != null) { return -1; } } if (this.port == that.port) { factor += 4; } else { if (this.port != -1 && that.port != -1) { return -1; } } if (LangUtils.equals(this.protocol, that.protocol)) { factor += 8; } else { if (this.protocol != null && that.protocol != null) { return -1; } } if (LangUtils.equals(this.host, that.host)) { factor += 16; } else { if (this.host != null && that.host != null) { return -1; } } return factor; } AuthScope(
            final String protocol,
            final String host,
            final int port,
            final String realm,
            final String schemeName);  AuthScope(
            final HttpHost origin,
            final String realm,
            final String schemeName);  AuthScope(final HttpHost origin);  AuthScope(final String host, final int port);  AuthScope(final AuthScope authScope); String getProtocol(); String getHost(); int getPort(); String getRealm(); String getSchemeName(); int match(final AuthScope that); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testScopeMatching() { final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme"); final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme"); Assert.assertTrue(authscope1.match(authscope2) < 0); int m1 = authscope1.match(new AuthScope(null, null, -1, null, "somescheme")); int m2 = authscope1.match(new AuthScope(null, null, -1, "somerealm", null)); Assert.assertTrue(m2 > m1); m1 = authscope1.match(new AuthScope(null, null, -1, null, "somescheme")); m2 = authscope1.match(new AuthScope(null, null, -1, "somerealm", null)); Assert.assertTrue(m2 > m1); m1 = authscope1.match(new AuthScope(null, null, -1, "somerealm", "somescheme")); m2 = authscope1.match(new AuthScope(null, null, 80, null, null)); Assert.assertTrue(m2 > m1); m1 = authscope1.match(new AuthScope(null, null, 80, "somerealm", "somescheme")); m2 = authscope1.match(new AuthScope(null, "somehost", -1, null, null)); Assert.assertTrue(m2 > m1); m1 = authscope1.match(new AuthScope(null, null, 80, "somerealm", "somescheme")); m2 = authscope1.match(new AuthScope(null, "somehost", -1, null, null)); Assert.assertTrue(m2 > m1); m1 = authscope1.match(new AuthScope(null, null, -1, null, null)); m2 = authscope1.match(new AuthScope(null, null, -1, null, "somescheme")); Assert.assertTrue(m2 > m1); }