Browse Source

Fix the unit test case issues in DOS/Windows platform by picking the new line char dynamically. (#2558)

* Fix the unit test case issues in DOS/Windows platform by picking th new line char dynamically.

* Fix new code comments, and to test in windows machine.

* Missed to load static

* Comment fixes

* Removing unused imports
pull/2482/head
penmetsaa 5 years ago
committed by GitHub
parent
commit
480f4d49f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions
  1. +6
    -3
      metadata/src/test/java/com/google/i18n/phonenumbers/metadata/model/AltFormatsSchemaTest.java
  2. +7
    -3
      metadata/src/test/java/com/google/i18n/phonenumbers/metadata/model/CommentsSchemaTest.java
  3. +5
    -2
      metadata/src/test/java/com/google/i18n/phonenumbers/metadata/table/CsvTableTest.java

+ 6
- 3
metadata/src/test/java/com/google/i18n/phonenumbers/metadata/model/AltFormatsSchemaTest.java View File

@ -15,9 +15,9 @@
*/
package com.google.i18n.phonenumbers.metadata.model;
import static com.google.common.base.StandardSystemProperty.LINE_SEPARATOR;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
@ -33,6 +33,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class AltFormatsSchemaTest {
private static final String NEW_LINE = LINE_SEPARATOR.value();
@Test
public void testSimple_export() throws IOException {
assertThat(
@ -98,14 +100,15 @@ public class AltFormatsSchemaTest {
try (StringWriter out = new StringWriter()) {
AltFormatsSchema.exportCsv(out, Arrays.asList(altFormats));
// Ignore trailing empty lines.
return Splitter.on('\n').splitToList(CharMatcher.is('\n').trimTrailingFrom(out.toString()));
return Splitter.on(NEW_LINE).omitEmptyStrings().splitToList(out.toString());
}
}
private static ImmutableList<AltFormatSpec> importCsv(String... lines)
throws IOException {
// Add a trailing newline, since that's what we expect in the real CSV files.
StringReader file = new StringReader(Joiner.on('\n').join(lines) + "\n");
StringReader file = new StringReader(Joiner.on(NEW_LINE).join(lines) + NEW_LINE);
return AltFormatsSchema.importAltFormats(file);
}
}

+ 7
- 3
metadata/src/test/java/com/google/i18n/phonenumbers/metadata/model/CommentsSchemaTest.java View File

@ -15,12 +15,12 @@
*/
package com.google.i18n.phonenumbers.metadata.model;
import static com.google.common.base.StandardSystemProperty.LINE_SEPARATOR;
import static com.google.common.truth.Truth.assertThat;
import static com.google.i18n.phonenumbers.metadata.model.NumberingScheme.Comment.anchor;
import static com.google.i18n.phonenumbers.metadata.proto.Types.XmlNumberType.XML_FIXED_LINE;
import static com.google.i18n.phonenumbers.metadata.proto.Types.XmlNumberType.XML_MOBILE;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
@ -38,6 +38,9 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class CommentsSchemaTest {
private static final String NEW_LINE = LINE_SEPARATOR.value();
private static final PhoneRegion REGION_US = PhoneRegion.of("US");
private static final PhoneRegion REGION_CA = PhoneRegion.of("CA");
@ -143,14 +146,15 @@ public class CommentsSchemaTest {
try (StringWriter out = new StringWriter()) {
CommentsSchema.exportCsv(out, Arrays.asList(comments));
// Ignore trailing empty lines.
return Splitter.on('\n').splitToList(CharMatcher.is('\n').trimTrailingFrom(out.toString()));
return Splitter.on(NEW_LINE).omitEmptyStrings().splitToList(out.toString());
}
}
private static ImmutableList<Comment> importCsv(String... lines)
throws IOException {
// Add a trailing newline, since that's what we expect in the real CSV files.
StringReader file = new StringReader(Joiner.on('\n').join(lines) + "\n");
StringReader file = new StringReader(Joiner.on(NEW_LINE).join(lines) + NEW_LINE);
return CommentsSchema.importComments(file);
}
}

+ 5
- 2
metadata/src/test/java/com/google/i18n/phonenumbers/metadata/table/CsvTableTest.java View File

@ -16,6 +16,7 @@
package com.google.i18n.phonenumbers.metadata.table;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.StandardSystemProperty.LINE_SEPARATOR;
import static com.google.common.truth.Truth.assertThat;
import static com.google.i18n.phonenumbers.metadata.model.RangesTableSchema.AREA_CODE_LENGTH;
import static com.google.i18n.phonenumbers.metadata.model.RangesTableSchema.COMMENT;
@ -64,6 +65,8 @@ public class CsvTableTest {
private static final Column<Boolean> REGION_CA = REGIONS.getColumn(PhoneRegion.of("CA"));
private static final Column<Boolean> REGION_US = REGIONS.getColumn(PhoneRegion.of("US"));
private static final String NEW_LINE = LINE_SEPARATOR.value();
@Test
public void testRangeTableExport() throws IOException {
ImmutableList<Column<?>> columns =
@ -91,7 +94,6 @@ public class CsvTableTest {
table.put(PhoneRegion.of("US"), ValidNumberType.PREMIUM_RATE, DigitSequence.of("945123456"));
table.put(PhoneRegion.of("CA"), ValidNumberType.MOBILE, DigitSequence.of("555123456"));
// Ordering is well defined in the CSV output.
// TODO: Consider making columns able to identify if their values need CSV escaping.
CsvTable<ExampleNumberKey> csv = ExamplesTableSchema.toCsv(table);
assertCsv(csv,
"Region ; Type ; Number",
@ -264,7 +266,7 @@ public class CsvTableTest {
}
private static String join(String... lines) {
return String.join("\n", lines) + "\n";
return String.join(NEW_LINE, lines) + NEW_LINE;
}
private static RangeKey key(String spec, Integer... lengths) {
@ -273,3 +275,4 @@ public class CsvTableTest {
return RangeKey.create(prefix, ImmutableSet.copyOf(lengths));
}
}

Loading…
Cancel
Save