From 9f889fa86753cdfff50bd9df969ea2f04291c128 Mon Sep 17 00:00:00 2001 From: AliIman Date: Tue, 15 Jun 2021 21:55:18 -0400 Subject: [PATCH] Refactored four test method pairs --- .../common/jimfs/JimfsInputStreamTest.java | 24 ++++---- .../common/jimfs/PathNormalizationTest.java | 58 ++++++++----------- .../common/jimfs/WindowsPathTypeTest.java | 37 +++++------- 3 files changed, 51 insertions(+), 68 deletions(-) diff --git a/jimfs/src/test/java/com/google/common/jimfs/JimfsInputStreamTest.java b/jimfs/src/test/java/com/google/common/jimfs/JimfsInputStreamTest.java index 94cc5f47..a9c029a5 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/JimfsInputStreamTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/JimfsInputStreamTest.java @@ -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 @@ -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); + } } diff --git a/jimfs/src/test/java/com/google/common/jimfs/PathNormalizationTest.java b/jimfs/src/test/java/com/google/common/jimfs/PathNormalizationTest.java index 23b28b4a..7a61f8db 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/PathNormalizationTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/PathNormalizationTest.java @@ -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 @@ -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. */ @@ -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"); + } } diff --git a/jimfs/src/test/java/com/google/common/jimfs/WindowsPathTypeTest.java b/jimfs/src/test/java/com/google/common/jimfs/WindowsPathTypeTest.java index 2da1280a..d1df74c1 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/WindowsPathTypeTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/WindowsPathTypeTest.java @@ -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 @@ -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) { + } + } }