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

Refactored four test method pairs #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -75,21 +75,13 @@ public void testRead_wholeArray_arraySmaller() throws IOException {
}

@Test
public void testRead_partialArray() throws IOException {
JimfsInputStream in = newInputStream(1, 2, 3, 4, 5, 6, 7, 8);
byte[] bytes = new byte[12];
assertThat(in.read(bytes, 0, 8)).isEqualTo(8);
assertArrayEquals(bytes(1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0), bytes);
assertEmpty(in);
public void testRead_partialArray() throws Exception {
this.jimfsInputStreamTestTestRead_partialTemplate(8);
}

@Test
public void testRead_partialArray_sliceLarger() throws IOException {
JimfsInputStream in = newInputStream(1, 2, 3, 4, 5, 6, 7, 8);
byte[] bytes = new byte[12];
assertThat(in.read(bytes, 0, 10)).isEqualTo(8);
assertArrayEquals(bytes(1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0), bytes);
assertEmpty(in);
public void testRead_partialArray_sliceLarger() throws Exception {
this.jimfsInputStreamTestTestRead_partialTemplate(10);
}

@Test
Expand Down Expand Up @@ -237,4 +229,12 @@ private static void assertEmpty(JimfsInputStream in) throws IOException {
assertThat(in.read(new byte[10], 1, 5)).isEqualTo(-1);
assertThat(in.available()).isEqualTo(0);
}

public void jimfsInputStreamTestTestRead_partialTemplate(int i1) throws Exception {
JimfsInputStream in = newInputStream(1, 2, 3, 4, 5, 6, 7, 8);
byte[] bytes = new byte[12];
assertThat(in.read(bytes, 0, i1)).isEqualTo(8);
assertArrayEquals(bytes(1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0), bytes);
assertEmpty(in);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,12 @@ public void testCaseFoldAscii_pattern() {

@Test
public void testNormalizeNfc_pattern() {
normalizations = ImmutableSet.of(NFC);
assertNormalizedPatternMatches("foo", "foo");
assertNormalizedPatternDoesNotMatch("foo", "FOO");
assertNormalizedPatternDoesNotMatch("FOO", "foo");
assertNormalizedPatternMatches("Am\u00e9lie", "Ame\u0301lie");
assertNormalizedPatternDoesNotMatch("Am\u00e9lie", "AME\u0301LIE");
this.pathNormalizationTestTestNormalizeTemplate(NFC);
}

@Test
public void testNormalizeNfd_pattern() {
normalizations = ImmutableSet.of(NFD);
assertNormalizedPatternMatches("foo", "foo");
assertNormalizedPatternDoesNotMatch("foo", "FOO");
assertNormalizedPatternDoesNotMatch("FOO", "foo");
assertNormalizedPatternMatches("Am\u00e9lie", "Ame\u0301lie");
assertNormalizedPatternDoesNotMatch("Am\u00e9lie", "AME\u0301LIE");
this.pathNormalizationTestTestNormalizeTemplate(NFD);
}

@Test
Expand Down Expand Up @@ -275,32 +265,12 @@ public void testNormalizeNfdCaseFold_pattern() {

@Test
public void testNormalizeNfcCaseFoldAscii_pattern() {
normalizations = ImmutableSet.of(NFC, CASE_FOLD_ASCII);
assertNormalizedPatternMatches("foo", "foo");
assertNormalizedPatternMatches("foo", "FOO");
assertNormalizedPatternMatches("FOO", "foo");

// these are all a bit fuzzy as when CASE_INSENSITIVE is present but not UNICODE_CASE, ASCII
// only strings are expected
assertNormalizedPatternMatches("Ame\u0301lie", "AME\u0301LIE");
assertNormalizedPatternDoesNotMatch("Am\u00e9lie", "AM\u00c9LIE");
assertNormalizedPatternMatches("Am\u00e9lie", "Ame\u0301lie");
assertNormalizedPatternMatches("AM\u00c9LIE", "AME\u0301LIE");
this.pathNormalizationTestTestNormalizeCaseFoldAscii_patternTemplate(NFC);
}

@Test
public void testNormalizeNfdCaseFoldAscii_pattern() {
normalizations = ImmutableSet.of(NFD, CASE_FOLD_ASCII);
assertNormalizedPatternMatches("foo", "foo");
assertNormalizedPatternMatches("foo", "FOO");
assertNormalizedPatternMatches("FOO", "foo");

// these are all a bit fuzzy as when CASE_INSENSITIVE is present but not UNICODE_CASE, ASCII
// only strings are expected
assertNormalizedPatternMatches("Ame\u0301lie", "AME\u0301LIE");
assertNormalizedPatternDoesNotMatch("Am\u00e9lie", "AM\u00c9LIE");
assertNormalizedPatternMatches("Am\u00e9lie", "Ame\u0301lie");
assertNormalizedPatternMatches("AM\u00c9LIE", "AME\u0301LIE");
this.pathNormalizationTestTestNormalizeCaseFoldAscii_patternTemplate(NFD);
}

/** Asserts that the given strings normalize to the same string using the current normalizer. */
Expand Down Expand Up @@ -348,4 +318,24 @@ private void assertNormalizedPatternDoesNotMatch(String first, String second) {
"pattern '" + pattern + "' should not match '" + first + "'",
pattern.matcher(first).matches());
}

public void pathNormalizationTestTestNormalizeCaseFoldAscii_patternTemplate(PathNormalization pathNormalization1) {
normalizations = ImmutableSet.of(pathNormalization1, CASE_FOLD_ASCII);
assertNormalizedPatternMatches("foo", "foo");
assertNormalizedPatternMatches("foo", "FOO");
assertNormalizedPatternMatches("FOO", "foo");
assertNormalizedPatternMatches("Ame\u0301lie", "AME\u0301LIE");
assertNormalizedPatternDoesNotMatch("Am\u00e9lie", "AM\u00c9LIE");
assertNormalizedPatternMatches("Am\u00e9lie", "Ame\u0301lie");
assertNormalizedPatternMatches("AM\u00c9LIE", "AME\u0301LIE");
}

public void pathNormalizationTestTestNormalizeTemplate(PathNormalization pathNormalization1) {
normalizations = ImmutableSet.of(pathNormalization1);
assertNormalizedPatternMatches("foo", "foo");
assertNormalizedPatternDoesNotMatch("foo", "FOO");
assertNormalizedPatternDoesNotMatch("FOO", "foo");
assertNormalizedPatternMatches("Am\u00e9lie", "Ame\u0301lie");
assertNormalizedPatternDoesNotMatch("Am\u00e9lie", "AME\u0301LIE");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,12 @@ public void testWindows() {

@Test
public void testWindows_relativePathsWithDriveRoot_unsupported() {
try {
windows().parsePath("C:");
fail();
} catch (InvalidPathException expected) {
}

try {
windows().parsePath("C:foo\\bar");
fail();
} catch (InvalidPathException expected) {
}
this.windowsPathTypeTestTestTemplate("C:", "C:foo\\bar");
}

@Test
public void testWindows_absolutePathOnCurrentDrive_unsupported() {
try {
windows().parsePath("\\foo\\bar");
fail();
} catch (InvalidPathException expected) {
}

try {
windows().parsePath("\\");
fail();
} catch (InvalidPathException expected) {
}
this.windowsPathTypeTestTestTemplate("\\foo\\bar", "\\");
}

@Test
Expand Down Expand Up @@ -219,4 +199,17 @@ public void testWindows_uriRoundTrips_unc() {
assertUriRoundTripsCorrectly(PathType.windows(), "\\\\host\\share\\foo bar");
assertUriRoundTripsCorrectly(PathType.windows(), "\\\\host\\share\\foo bar\\baz");
}

public void windowsPathTypeTestTestTemplate(String string1, String string2) {
try {
windows().parsePath(string1);
fail();
} catch (InvalidPathException expected) {
}
try {
windows().parsePath(string2);
fail();
} catch (InvalidPathException expected) {
}
}
}