Skip to content

Commit

Permalink
refactor(test): Remove redundant test
Browse files Browse the repository at this point in the history
  • Loading branch information
djansen-redhat committed Feb 16, 2017
1 parent d98d665 commit 4bd5866
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
Expand Up @@ -10,11 +10,10 @@

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -48,11 +47,15 @@ File createTempFile(Charset charset) throws Exception {
File testFile = File.createTempFile("test-properties-temp-" + charset, ".properties");
System.out.println(testFile);
assertThat(testFile.exists());
Map<String, String> entries = new HashMap<>();
Map<String, String> entries = new LinkedHashMap<>();
if (charset == StandardCharsets.ISO_8859_1) {
entries.put("line1", "ÀLine One");
entries.put("line2", "ÀLine Two");
entries.put("line3", "ÀLine Three");
} else if (charset == StandardCharsets.UTF_8) {
entries.put("line1", "¥Line One");
entries.put("line2", "¥Line Two");
entries.put("line3", "¥Line Three");
}
Properties resource = new Properties();
for (Map.Entry<String, String> entry : entries.entrySet()) {
Expand Down
Expand Up @@ -23,7 +23,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.*;
import java.net.URI;
import java.nio.charset.StandardCharsets;

import com.google.common.base.Charsets;
Expand All @@ -44,6 +43,7 @@

/**
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class PropertiesLatinOneAdapterTest extends PropertiesAbstractTest {

Expand All @@ -53,9 +53,11 @@ public void setup() {
}

@Test
public void parseLatinOneProperties() {
Resource resource = parseTestFile("test-properties-latin1.properties");
assertThat(resource.getTextFlows()).hasSize(3);
public void parseLatinOneProperties() throws Exception {
File latin1EncodedFile = createTempFile(StandardCharsets.ISO_8859_1);
Resource resource =
adapter.parseDocumentFile(latin1EncodedFile.toURI(), LocaleId.EN,
Optional.absent());
assertThat(resource.getTextFlows().get(0).getId()).isEqualTo(
"line1");
assertThat(resource.getTextFlows().get(0).getContents())
Expand Down Expand Up @@ -86,7 +88,10 @@ public void testTranslatedPropertiesDocument() throws Exception {
addTranslation(tResource, "line2", "ÀTbade metalkcta", ContentState.Translated);
addTranslation(tResource, "line3", "ÀKbade metalkcta", ContentState.NeedReview);

Resource resource = parseTestFile("test-properties-latin1.properties");
File latin1EncodedFile = createTempFile(StandardCharsets.ISO_8859_1);
Resource resource =
adapter.parseDocumentFile(latin1EncodedFile.toURI(), LocaleId.EN,
Optional.absent());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

adapter.writeTranslatedFile(outputStream,
Expand All @@ -107,16 +112,4 @@ private String toLatin1String(ByteArrayOutputStream outputStream)
throws UnsupportedEncodingException {
return outputStream.toString(Charsets.ISO_8859_1.name());
}

@Test
public void testLatin1encoding() throws Exception {
File latin1EncodedFile = createTempFile(StandardCharsets.ISO_8859_1);
Resource resource =
adapter.parseDocumentFile(latin1EncodedFile.toURI(), LocaleId.EN,
Optional.absent());
assertThat(resource.getTextFlows().get(0).getId()).isEqualTo(
"line1");
assertThat(resource.getTextFlows().get(0).getContents())
.containsExactly("ÀLine One");
}
}

This file was deleted.

0 comments on commit 4bd5866

Please sign in to comment.