Commit dc963684 authored by Brian Major's avatar Brian Major
Browse files

issue-10 - fix to GroupURI equals()

parent 07f9b1f1
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -156,16 +156,19 @@ public class GroupURI
    }

    @Override
    public boolean equals(Object rhs)
    public boolean equals(Object other)
    {
        if (rhs == null)
        if (other == null)
            return false;
        if (this == rhs)
        if (this == other)
            return true;
        if (rhs instanceof GroupURI)
        if (other instanceof GroupURI)
        {
            GroupURI vu = (GroupURI) rhs;
            return uri.toString().equals(vu.uri.toString());

            GroupURI oID = (GroupURI) other;
            String otherURI = getServiceIDString() + "?" + oID.getName();
            String thisURI = getServiceIDString() + "?" + this.getName();
            return thisURI.equals(otherURI);
        }
        return false;
    }
@@ -200,15 +203,20 @@ public class GroupURI
        return name;
    }

    public URI getServiceID()
    public String getServiceIDString()
    {
        String serviceID = uri.getScheme() +
        return uri.getScheme() +
            "://" +
            uri.getAuthority() +
            uri.getPath();
    }

    public URI getServiceID()
    {
        String serviceIDString = getServiceIDString();
        try
        {
            return new URI(serviceID);
            return new URI(serviceIDString);
        }
        catch (URISyntaxException e)
        {
+12 −0
Original line number Diff line number Diff line
@@ -18,6 +18,18 @@ public class GroupURITest
        Log4jInit.setLevel("ca.nrc.cadc.ac", Level.DEBUG);
    }

    @Test
    public void testEquals()
    {
        GroupURI uri1 = new GroupURI("ivo://example.org/gms?name");
        GroupURI uri2 = new GroupURI("ivo://example.org/gms?name");
        Assert.assertTrue(uri1.equals(uri2));

        uri1 = new GroupURI("ivo://example.org/gms?name");
        uri2 = new GroupURI("ivo://example.org/gms#name");
        Assert.assertTrue(uri1.equals(uri2));
    }

    @Test
    public void testMalformed()
    {