Skip to content

Commit

Permalink
Merge pull request #162 from nulab/fix-sonarcloud-maintainability-3
Browse files Browse the repository at this point in the history
fix: fix sonarcloud maintainability phase 3
  • Loading branch information
vvatanabe authored Aug 30, 2023
2 parents a4f95da + c77f699 commit d6bbaa2
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 30 deletions.
8 changes: 1 addition & 7 deletions src/main/java/com/nulabinc/zxcvbn/Pattern.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.nulabinc.zxcvbn;

@SuppressWarnings("java:S115")
public enum Pattern {
@SuppressWarnings("java:S115")
Bruteforce("bruteforce"),
@SuppressWarnings("java:S115")
Dictionary("dictionary"),
@SuppressWarnings("java:S115")
Spatial("spatial"),
@SuppressWarnings("java:S115")
Repeat("repeat"),
@SuppressWarnings("java:S115")
Sequence("sequence"),
@SuppressWarnings("java:S115")
Regex("regex"),
@SuppressWarnings("java:S115")
Date("date");

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private InputStream getResourceAsStreamWithFallback(String path) {
return null;
}

@SuppressWarnings("java:S1181")
private InputStream getResourceAsStream(ClassLoader cl, String path) {
try {
if (cl != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nulabinc/zxcvbn/matchers/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean match(final char c) {

private final String layout;

public AdjacentGraphBuilder(final String layout) {
protected AdjacentGraphBuilder(final String layout) {
this.layout = layout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class KeyboardLoader {

private final Resource resource;

public KeyboardLoader(final String name, final Resource resource) {
protected KeyboardLoader(final String name, final Resource resource) {
this.name = name;
this.resource = resource;
}
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/nulabinc/zxcvbn/matchers/L33tSubDict.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@

public class L33tSubDict implements Iterable<Map<Character, Character>> {

private final List<Map<Character, Character>> subDicts;
private final List<Map<Character, Character>> l33tSubDictionaries;

L33tSubDict(Map<Character, List<Character>> table) {
this.subDicts = buildSubDicts(table);
this.l33tSubDictionaries = buildSubDictionaries(table);
}

private List<Map<Character, Character>> buildSubDicts(
private List<Map<Character, Character>> buildSubDictionaries(
final Map<Character, List<Character>> table) {
final Set<List<String>> initialSubs = new LinkedHashSet<>();
initialSubs.add(new ArrayList<String>());
final Set<List<String>> subs = helper(table, table.keySet().iterator(), initialSubs);
final Set<List<String>> allCombinations =
generateCombinationsRecursively(table, table.keySet().iterator(), initialSubs);

List<Map<Character, Character>> subDicts = new ArrayList<>();
for (List<String> sub : subs) {
Map<Character, Character> subDict = new HashMap<>();
for (CharSequence ref : sub) {
subDict.put(ref.charAt(0), ref.charAt(1));
List<Map<Character, Character>> subDictionaries = new ArrayList<>();
for (List<String> combination : allCombinations) {
Map<Character, Character> subDictionary = new HashMap<>();
for (CharSequence pair : combination) {
subDictionary.put(pair.charAt(0), pair.charAt(1));
}
subDicts.add(subDict);
subDictionaries.add(subDictionary);
}
return subDicts;
return subDictionaries;
}

private Set<List<String>> helper(
private Set<List<String>> generateCombinationsRecursively(
final Map<Character, List<Character>> table,
final Iterator<Character> keysIterator,
final Set<List<String>> subs) {
Expand Down Expand Up @@ -65,11 +66,11 @@ private Set<List<String>> helper(
}
}

return helper(table, keysIterator, nextSubs);
return generateCombinationsRecursively(table, keysIterator, nextSubs);
}

@Override
public Iterator<Map<Character, Character>> iterator() {
return subDicts.iterator();
return l33tSubDictionaries.iterator();
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/nulabinc/zxcvbn/matchers/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public class Match {
public final int month;
public final int day;

@SuppressWarnings("java:S1104")
public Double baseGuesses;

@SuppressWarnings("java:S1104")
public Double guesses;

@SuppressWarnings("java:S1104")
public Double guessesLog10;

private Match(Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static Match createReversedDictionaryMatch(
.build();
}

@SuppressWarnings("java:S107")
public static Match createDictionaryL33tMatch(
int i,
int j,
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/com/nulabinc/zxcvbn/EdgeCaseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nulabinc.zxcvbn;

import static org.junit.Assert.assertNotNull;

import org.junit.Test;

public class EdgeCaseTest {
Expand All @@ -16,25 +18,25 @@ public void testWindowsNewlineInDate() {
buf.append((char) 10);
buf.append((char) 13);
buf.append("0101");
new Zxcvbn().measure(buf.toString());
assertNotNull(new Zxcvbn().measure(buf.toString()));
}

@Test
public void testUnixNewlineInDate() {
StringBuilder buf = new StringBuilder("PW2001");
buf.append((char) 13);
buf.append("0101");
new Zxcvbn().measure(buf.toString());
assertNotNull(new Zxcvbn().measure(buf.toString()));
}

@Test
public void testSpaceAfterDate() {
new Zxcvbn().measure("PW2009 ");
assertNotNull(new Zxcvbn().measure("PW2009 "));
}

/** Try to reproduce GitHub issue #34 */
@Test
public void testJustFourDigitNumber() {
new Zxcvbn().measure("8604 ");
assertNotNull(new Zxcvbn().measure("8604 "));
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/nulabinc/zxcvbn/MatchingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public SequenceMatchingSimpleTest(String password) {
public void testSequenceMatching() throws Exception {
Context context = StandardContext.build();
String msg = String.format("doesn't match length-%s sequences", password.length());
assertEquals(msg, new SequenceMatcher(context).execute(password).size(), 0);
assertEquals(msg, 0, new SequenceMatcher(context).execute(password).size());
}

@Parameterized.Parameters(name = "{0}")
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/nulabinc/zxcvbn/WipeableStringTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nulabinc.zxcvbn;

import static junit.framework.TestCase.*;
import static org.junit.Assert.assertNotEquals;

import java.nio.CharBuffer;
import org.junit.Test;
Expand All @@ -14,8 +15,8 @@ public void testHashCode() {

@Test
public void testEquals() {
assertTrue(new WipeableString("hello").equals("hello"));
assertFalse(new WipeableString("goodbye").equals("hello"));
assertEquals("hello", new WipeableString("hello").toString());
assertNotEquals("hello", new WipeableString("goodbye").toString());
}

@Test
Expand Down

0 comments on commit d6bbaa2

Please sign in to comment.