Skip to content

make Project/Group comparison case sensitive #4017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.configuration;

import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -252,16 +252,12 @@ public boolean match(String name) {

@Override
public int compareTo(Group o) {
return getName().toUpperCase(Locale.ROOT).compareTo(
o.getName().toUpperCase(Locale.ROOT));
return getName().compareTo(o.getName());
}

@Override
public int hashCode() {
int hash = 3;
hash = 41 * hash + (this.name == null ? 0 :
this.name.toUpperCase(Locale.ROOT).hashCode());
return hash;
return Objects.hashCode(name);
}

@Override
Expand All @@ -280,8 +276,7 @@ public boolean equals(Object obj) {
int numNull = (name == null ? 1 : 0) + (other.name == null ? 1 : 0);
switch (numNull) {
case 0:
return name.toUpperCase(Locale.ROOT).equals(
other.name.toUpperCase(Locale.ROOT));
return name.equals(other.name);
case 1:
return false;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
Expand Down Expand Up @@ -585,16 +585,12 @@ public static Project getByName(String name) {

@Override
public int compareTo(Project p2) {
return getName().toUpperCase(Locale.ROOT).compareTo(
p2.getName().toUpperCase(Locale.ROOT));
return getName().compareTo(p2.getName());
}

@Override
public int hashCode() {
int hash = 3;
hash = 41 * hash + (this.name == null ? 0 :
this.name.toUpperCase(Locale.ROOT).hashCode());
return hash;
return Objects.hashCode(name);
}

@Override
Expand All @@ -613,8 +609,7 @@ public boolean equals(Object obj) {
int numNull = (name == null ? 1 : 0) + (other.name == null ? 1 : 0);
switch (numNull) {
case 0:
return name.toUpperCase(Locale.ROOT).equals(
other.name.toUpperCase(Locale.ROOT));
return name.equals(other.name);
case 1:
return false;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.configuration;

Expand All @@ -39,14 +39,14 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class GroupTest {
class GroupTest {

/**
* Test that a {@code Group} instance can be encoded and decoded without
* errors.
*/
@Test
public void testEncodeDecode() {
void testEncodeDecode() {
// Create an exception listener to detect errors while encoding and
// decoding
final LinkedList<Exception> exceptions = new LinkedList<>();
Expand Down Expand Up @@ -79,7 +79,7 @@ public void testEncodeDecode() {
}

@Test
public void invalidPatternTest() {
void invalidPatternTest() {
testPattern("*dangling asterisk", false);
testPattern(".*(", false);
testPattern("+", false);
Expand All @@ -102,7 +102,7 @@ private void testPattern(String pattern, boolean valid) {
}

@Test
public void basicTest() {
void basicTest() {
Group g = new Group("Random name", "abcd");

assertEquals("Random name", g.getName());
Expand Down Expand Up @@ -140,7 +140,7 @@ public void basicTest() {
}

@Test
public void subgroupsTest() {
void subgroupsTest() {
Group g1 = new Group("Random name", "abcd");
Group g2 = new Group("Random name2", "efgh");
Group g3 = new Group("Random name3", "xyz");
Expand Down Expand Up @@ -177,7 +177,7 @@ public void subgroupsTest() {
}

@Test
public void projectTest() {
void projectTest() {
Group random1 = new Group("Random name", "abcd");
Group random2 = new Group("Random name2", "efgh");

Expand Down Expand Up @@ -205,19 +205,13 @@ public void projectTest() {
}

@Test
public void testEquality() {
void testEquality() {
Group g1 = new Group();
Group g2 = new Group();
assertEquals(g1, g2, "null == null");

g1 = new Group("name");
g2 = new Group("other");
assertNotEquals(g1, g2, "\"name\" != \"other\"");

g1 = new Group("name");
g2 = new Group("NAME");
assertEquals(g1, g2, "\"name\" == \"NAME\"");
assertEquals(g1, g1, "\"name\" == \"name\"");
assertEquals(g2, g2, "\"NAME\" == \"NAME\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,6 @@ void testEquality() {
g1 = new Project("name");
g2 = new Project("other");
assertNotEquals(g1, g2, "\"name\" != \"other\"");

g1 = new Project("name");
g2 = new Project("NAME");
assertEquals(g1, g2, "\"name\" == \"NAME\"");
assertEquals(g1, g1, "\"name\" == \"name\"");
assertEquals(g2, g2, "\"NAME\" == \"NAME\"");
}

@Test
Expand Down