Skip to content
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

Scanner for name repository is problematic when constants values are not unique #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -7,30 +7,40 @@
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.assertj.core.api.Assertions;
import org.junit.BeforeClass;
import org.junit.Test;

import com.google.common.collect.ImmutableSet;

import static org.assertj.core.api.Assertions.assertThat;

public class ClasspathConstantScannerTest {

public static final String A_TEST_VALUE_TO_BE_FOUND = "aTestValueToBeFound";

public static final String DUPLICATE_VALUE_A = "SAME";
public static final String DUPLICATE_VALUE_B = "SAME";

@BeforeClass
public static final void setUpBeforeClass() {
public static void setUpBeforeClass() {
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
}

@Test
public void test() {
long start = System.nanoTime();
public void testConstantIsFound() {
ClasspathConstantScanner scanner = new ClasspathConstantScanner(ImmutableSet.of("org.tensorics.core.util.names"));
NameRepository nameRepo = scanner.scan();
assertThat(nameRepo.nameFor(A_TEST_VALUE_TO_BE_FOUND)).isEqualTo("A_TEST_VALUE_TO_BE_FOUND");
}

@Test
public void testDuplicateConstantEntry() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test that should work after the improvements

ClasspathConstantScanner scanner = new ClasspathConstantScanner(ImmutableSet.of("org.tensorics.core.util.names"));
NameRepository nameRepo = scanner.scan();
long end = System.nanoTime();
System.out.println("Done in " + Double.valueOf((end - start) / 1000000) / 1e3 + " secs.");
Assertions.assertThat(nameRepo.nameFor(A_TEST_VALUE_TO_BE_FOUND)).isEqualTo("A_TEST_VALUE_TO_BE_FOUND");

assertThat(nameRepo.nameFor(DUPLICATE_VALUE_A)).isEqualTo("DUPLICATE_VALUE_A");
assertThat(nameRepo.nameFor(DUPLICATE_VALUE_B)).isEqualTo("DUPLICATE_VALUE_B");
}

}