Permalink
Browse files

refactor: migrate to assertJ (#558)

  • Loading branch information...
aeng committed Oct 6, 2017
1 parent 1435314 commit c973f7df0f61ddedb72fe6809656834a1b124d9e
Showing with 522 additions and 663 deletions.
  1. +6 −0 client/pom.xml
  2. +2 −2 client/zanata-cli/pom.xml
  3. +5 −4 client/zanata-client-commands/pom.xml
  4. +3 −4 client/zanata-client-commands/src/test/java/org/zanata/client/TempTransFileRule.java
  5. +28 −35 ...t/zanata-client-commands/src/test/java/org/zanata/client/commands/FileMappingRuleHandlerTest.java
  6. +7 −8 client/zanata-client-commands/src/test/java/org/zanata/client/commands/HTTPMockContainer.java
  7. +19 −23 client/zanata-client-commands/src/test/java/org/zanata/client/commands/OptionsUtilTest.java
  8. +8 −9 client/zanata-client-commands/src/test/java/org/zanata/client/commands/PutUserOptionsImplTest.java
  9. +4 −6 client/zanata-client-commands/src/test/java/org/zanata/client/commands/TransFileResolverTest.java
  10. +16 −19 client/zanata-client-commands/src/test/java/org/zanata/client/commands/UpdateCheckerTest.java
  11. +8 −9 client/zanata-client-commands/src/test/java/org/zanata/client/commands/init/InitCommandTest.java
  12. +12 −14 ...anata-client-commands/src/test/java/org/zanata/client/commands/init/ProjectConfigHandlerTest.java
  13. +6 −7 ...ata-client-commands/src/test/java/org/zanata/client/commands/init/ProjectIterationPromptTest.java
  14. +12 −13 client/zanata-client-commands/src/test/java/org/zanata/client/commands/init/ProjectPromptTest.java
  15. +21 −34 .../zanata-client-commands/src/test/java/org/zanata/client/commands/init/SourceConfigPromptTest.java
  16. +11 −12 ...t/zanata-client-commands/src/test/java/org/zanata/client/commands/init/TransConfigPromptTest.java
  17. +8 −10 ...t/zanata-client-commands/src/test/java/org/zanata/client/commands/init/UserConfigHandlerTest.java
  18. +7 −10 ...ata-client-commands/src/test/java/org/zanata/client/commands/pull/GettextDirStrategyPullTest.java
  19. +8 −10 ...zanata-client-commands/src/test/java/org/zanata/client/commands/pull/GettextPullStrategyTest.java
  20. +9 −12 ...ata-client-commands/src/test/java/org/zanata/client/commands/pull/PropertiesStrategyPullTest.java
  21. +3 −6 client/zanata-client-commands/src/test/java/org/zanata/client/commands/pull/RawPullStrategyTest.java
  22. +9 −11 ...t/zanata-client-commands/src/test/java/org/zanata/client/commands/pull/XliffStrategyPullTest.java
  23. +8 −10 client/zanata-client-commands/src/test/java/org/zanata/client/commands/pull/XmlStrategyPullTest.java
  24. +10 −11 .../zanata-client-commands/src/test/java/org/zanata/client/commands/push/GettextDirStrategyTest.java
  25. +9 −10 ...zanata-client-commands/src/test/java/org/zanata/client/commands/push/GettextPushStrategyTest.java
  26. +5 −10 .../zanata-client-commands/src/test/java/org/zanata/client/commands/push/PropertiesStrategyTest.java
  27. +9 −13 client/zanata-client-commands/src/test/java/org/zanata/client/commands/push/RawPushCommandTest.java
  28. +5 −6 client/zanata-client-commands/src/test/java/org/zanata/client/commands/push/RawPushStrategyTest.java
  29. +3 −6 client/zanata-client-commands/src/test/java/org/zanata/client/commands/push/XliffStrategyTest.java
  30. +3 −6 client/zanata-client-commands/src/test/java/org/zanata/client/commands/push/XmlStrategyTest.java
  31. +15 −20 client/zanata-client-commands/src/test/java/org/zanata/client/config/ZanataConfigTest.java
  32. +17 −16 ...zanata-client-commands/src/test/java/org/zanata/client/integration/PushPullFileProjectITCase.java
  33. +14 −16 client/zanata-client-commands/src/test/java/org/zanata/client/integration/PushPullGettextITCase.java
  34. +10 −11 client/zanata-client-commands/src/test/java/org/zanata/client/util/VersionComparatorTest.java
  35. +2 −7 client/zanata-rest-client/pom.xml
  36. +4 −6 client/zanata-rest-client/src/test/java/org/zanata/rest/client/AccountClientTest.java
  37. +6 −7 client/zanata-rest-client/src/test/java/org/zanata/rest/client/ApiKeyHeaderFilterTest.java
  38. +7 −8 client/zanata-rest-client/src/test/java/org/zanata/rest/client/AsyncProcessClientTest.java
  39. +3 −4 client/zanata-rest-client/src/test/java/org/zanata/rest/client/CopyTransClientTest.java
  40. +9 −11 client/zanata-rest-client/src/test/java/org/zanata/rest/client/FileResourceClientTest.java
  41. +3 −4 client/zanata-rest-client/src/test/java/org/zanata/rest/client/GlossaryClientTest.java
  42. +31 −45 client/zanata-rest-client/src/test/java/org/zanata/rest/client/InvalidContentTypeFilterTest.java
  43. +4 −5 client/zanata-rest-client/src/test/java/org/zanata/rest/client/ProjectClientTest.java
  44. +4 −6 client/zanata-rest-client/src/test/java/org/zanata/rest/client/ProjectIterationClientTest.java
  45. +3 −4 client/zanata-rest-client/src/test/java/org/zanata/rest/client/ProjectsClientTest.java
  46. +3 −4 client/zanata-rest-client/src/test/java/org/zanata/rest/client/RestClientFactoryTest.java
  47. +6 −7 client/zanata-rest-client/src/test/java/org/zanata/rest/client/SourceDocResourceClientTest.java
  48. +9 −10 client/zanata-rest-client/src/test/java/org/zanata/rest/client/StatisticsResourceClientTest.java
  49. +2 −3 client/zanata-rest-client/src/test/java/org/zanata/rest/client/TransDocResourceClientTest.java
  50. +3 −8 common/pom.xml
  51. +7 −14 common/zanata-adapter-glossary/src/test/java/org/zanata/adapter/glossary/GlossaryCSVReaderTest.java
  52. +3 −5 common/zanata-adapter-glossary/src/test/java/org/zanata/adapter/glossary/GlossaryCSVWriterTest.java
  53. +3 −5 common/zanata-adapter-glossary/src/test/java/org/zanata/adapter/glossary/GlossaryPoReaderTest.java
  54. +4 −5 common/zanata-adapter-glossary/src/test/java/org/zanata/adapter/glossary/GlossaryPoWriterTest.java
  55. +19 −22 common/zanata-adapter-po/src/test/java/org/zanata/adapter/po/PoReader2Test.java
  56. +8 −9 common/zanata-adapter-properties/src/test/java/org/zanata/adapter/properties/PropReaderTest.java
  57. +28 −31 common/zanata-adapter-xliff/src/test/java/org/zanata/adapter/xliff/XliffReaderTest.java
  58. +5 −10 common/zanata-adapter-xliff/src/test/java/org/zanata/adapter/xliff/XliffWriterTest.java
  59. +9 −12 common/zanata-common-util/src/test/java/org/zanata/util/HashUtilTest.java
  60. +17 −18 common/zanata-common-util/src/test/java/org/zanata/util/PathUtilTest.java
View
@@ -224,6 +224,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
@@ -104,8 +104,8 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -114,8 +114,8 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -158,8 +158,9 @@
<artifactId>simple</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
@@ -30,8 +30,7 @@
import com.google.common.io.Files;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* This class can be used as a JUnit rule to create temporary translation files.
@@ -57,8 +56,8 @@ public File createTransFileRelativeToTransDir(String path)
File file = new File(transDir, path);
File parentFile = file.getParentFile();
parentFile.mkdirs();
assertThat(parentFile.exists(), is(true));
assertThat(file.createNewFile(), is(true));
assertThat(parentFile.exists()).isTrue();
assertThat(file.createNewFile()).isTrue();
return file;
}
@@ -25,14 +25,12 @@
import java.util.EnumMap;
import com.google.common.base.Optional;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.zanata.client.commands.push.PushOptionsImpl;
import org.zanata.client.config.FileMappingRule;
import org.zanata.client.config.LocaleMapping;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.zanata.client.commands.FileMappingRuleHandler.Placeholders;
import static org.zanata.client.commands.FileMappingRuleHandler.isRuleValid;
@@ -42,30 +40,25 @@
@Test
public void canCheckSyntaxErrorInTheRule() {
assertThat("unbalanced brace", isRuleValid("{a"), equalTo(false));
assertThat("unbalanced brace", isRuleValid("a}"), equalTo(false));
assertThat("missing brace", isRuleValid("a"), equalTo(false));
assertThat("invalid placeholder",
isRuleValid("{a}"), equalTo(false));
assertThat("missing mandatory placeholder",
isRuleValid("{path}"), equalTo(false));
assertThat(isRuleValid(
"{path}/{locale_with_underscore}.po"), equalTo(true));
assertThat(isRuleValid(
"{path}/../{locale}/{filename}.po"), equalTo(true));
assertThat(isRuleValid("{a")).as("unbalanced brace").isFalse();
assertThat(isRuleValid("a}")).as("unbalanced brace").isFalse();
assertThat(isRuleValid("a")).as("missing brace").isFalse();
assertThat(isRuleValid("{a}")).as("invalid placeholder").isFalse();
assertThat(isRuleValid("{path}")).as("missing mandatory placeholder")
.isFalse();
assertThat(isRuleValid("{path}/{locale_with_underscore}.po")).isTrue();
assertThat(isRuleValid("{path}/../{locale}/{filename}.po")).isTrue();
}
@Test
public void willReturnTransFileRelativePath() {
assertThat(getTransFile("pot/message.pot", "fr",
"{path}/../{locale}/{filename}.po"),
Matchers.equalTo("fr/message.po"));
"{path}/../{locale}/{filename}.po")).isEqualTo("fr/message.po");
assertThat(getTransFile("./message.pot", "fr",
"{path}/{locale_with_underscore}.po"),
Matchers.equalTo("fr.po"));
"{path}/{locale_with_underscore}.po")).isEqualTo("fr.po");
assertThat(getTransFile("a/path/message.odt", "de-DE",
"{path}/{locale_with_underscore}_{filename}.{extension}"),
Matchers.equalTo("a/path/de_DE_message.odt"));
"{path}/{locale_with_underscore}_{filename}.{extension}"))
.isEqualTo("a/path/de_DE_message.odt");
}
@Test
@@ -76,7 +69,7 @@ public void ifNoPatternWillUseProjectType() {
"{path}/{locale_with_underscore}.po"), opts);
assertThat(handler.getRelativeTransFilePathForSourceDoc(
DocNameWithExt.from("message.pot"),
new LocaleMapping("zh"), Optional.<String>absent()), Matchers.equalTo("zh.po"));
new LocaleMapping("zh"), Optional.<String>absent())).isEqualTo("zh.po");
}
private String getTransFile(String sourceFile, String locale, String rule) {
@@ -92,23 +85,23 @@ public void canGetPartsFromFullFilename() {
EnumMap<Placeholders, String> map =
FileMappingRuleHandler.parseToMap("foo/message.pot",
new LocaleMapping("zh-CN", "zh-Hans"), Optional.<String>absent());
assertThat(map, Matchers.hasEntry(Placeholders.path, "foo"));
assertThat(map, Matchers.hasEntry(Placeholders.filename, "message"));
assertThat(map, Matchers.hasEntry(Placeholders.extension, "pot"));
assertThat(map, Matchers.hasEntry(Placeholders.locale, "zh-Hans"));
assertThat(map, Matchers.hasEntry(Placeholders.localeWithUnderscore, "zh_Hans"));
assertThat(map).containsEntry(Placeholders.path, "foo");
assertThat(map).containsEntry(Placeholders.filename, "message");
assertThat(map).containsEntry(Placeholders.extension, "pot");
assertThat(map).containsEntry(Placeholders.locale, "zh-Hans");
assertThat(map).containsEntry(Placeholders.localeWithUnderscore, "zh_Hans");
}
@Test
public void canGetPartsFromFullFilename2() {
EnumMap<Placeholders, String> map =
FileMappingRuleHandler.parseToMap("foo/message.pot",
new LocaleMapping("zh-CN", "zh-Hans"), Optional.of("po"));
assertThat(map, Matchers.hasEntry(Placeholders.path, "foo"));
assertThat(map, Matchers.hasEntry(Placeholders.filename, "message"));
assertThat(map, Matchers.hasEntry(Placeholders.extension, "po"));
assertThat(map, Matchers.hasEntry(Placeholders.locale, "zh-Hans"));
assertThat(map, Matchers.hasEntry(Placeholders.localeWithUnderscore, "zh_Hans"));
assertThat(map).containsEntry(Placeholders.path, "foo");
assertThat(map).containsEntry(Placeholders.filename, "message");
assertThat(map).containsEntry(Placeholders.extension, "po");
assertThat(map).containsEntry(Placeholders.locale, "zh-Hans");
assertThat(map).containsEntry(Placeholders.localeWithUnderscore, "zh_Hans");
}
@Test
@@ -118,12 +111,12 @@ public void canTestApplicable() {
new FileMappingRule("**/*.odt",
"{locale}/{filename}.{extension}"), opts);
assertThat(handler.isApplicable(
DocNameWithExt.from("test/doc.odt")), equalTo(true));
DocNameWithExt.from("test/doc.odt"))).isTrue();
assertThat(handler.isApplicable(
DocNameWithExt.from("test/doc.pot")), equalTo(false));
DocNameWithExt.from("test/doc.pot"))).isFalse();
assertThat(handler.isApplicable(
DocNameWithExt.from("doc.pot")), equalTo(false));
DocNameWithExt.from("doc.pot"))).isFalse();
assertThat(handler.isApplicable(
DocNameWithExt.from("doc.odt")), equalTo(true));
DocNameWithExt.from("doc.odt"))).isTrue();
}
}
@@ -4,7 +4,6 @@
import java.io.PrintStream;
import java.util.Map;
import org.hamcrest.Matcher;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.Status;
@@ -22,10 +21,10 @@
private static final Logger log =
LoggerFactory.getLogger(HTTPMockContainer.class);
private final Map<Matcher<String>, StatusAndContent> pathToResponseMap;
private final Map<String, StatusAndContent> pathToResponseMap;
public HTTPMockContainer(
Map<Matcher<String>, StatusAndContent> pathToResponseMap) {
Map<String, StatusAndContent> pathToResponseMap) {
this.pathToResponseMap = pathToResponseMap;
}
@@ -64,9 +63,9 @@ public void handle(Request request, Response response) {
}
private StatusAndContent tryMatchPath(String path) {
for (Map.Entry<Matcher<String>, StatusAndContent> entry : pathToResponseMap
for (Map.Entry<String, StatusAndContent> entry : pathToResponseMap
.entrySet()) {
Matcher<String> pathMatcher = entry.getKey();
String pathMatcher = entry.getKey();
if (pathMatcher.matches(path)) {
return entry.getValue();
}
@@ -76,21 +75,21 @@ private StatusAndContent tryMatchPath(String path) {
}
public static class Builder {
private ImmutableMap.Builder<Matcher<String>, StatusAndContent> mapBuilder =
private ImmutableMap.Builder<String, StatusAndContent> mapBuilder =
ImmutableMap.builder();
public static Builder builder() {
return new Builder();
}
public Builder onPathReturnOk(Matcher<String> pathMatcher,
public Builder onPathReturnOk(String pathMatcher,
String content) {
mapBuilder.put(pathMatcher,
new StatusAndContent(Status.OK, content));
return this;
}
public Builder onPathReturnStatus(Matcher<String> pathMatcher,
public Builder onPathReturnStatus(String pathMatcher,
int status, String content) {
mapBuilder.put(pathMatcher,
new StatusAndContent(Status.getStatus(status), content));
@@ -1,8 +1,6 @@
package org.zanata.client.commands;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isA;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Question;
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Warning;
@@ -16,7 +14,6 @@
import javax.xml.bind.JAXBException;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -76,18 +73,18 @@ public void willApplyConfigFromFileIfNotSetInOptions() throws Exception {
OptionsUtil.applyIncludesAndExcludesFromProjectConfig(opts, config);
// Then:
assertThat(opts.getSrcDir(), equalTo(new File("a")));
assertThat(opts.getTransDir(), equalTo(new File("b")));
assertThat(opts.getIncludes(), Matchers.contains("*.properties"));
assertThat(opts.getExcludes(), Matchers.contains("a.properties"));
assertThat(opts.getSrcDir()).isEqualTo(new File("a"));
assertThat(opts.getTransDir()).isEqualTo(new File("b"));
assertThat(opts.getIncludes()).contains("*.properties");
assertThat(opts.getExcludes()).contains("a.properties");
}
@Test
public void willSetToDefaultValueIfNeitherHasValue() {
OptionsUtil.applySrcDirAndTransDirFromProjectConfig(opts, config);
assertThat(opts.getSrcDir(), equalTo(new File(".")));
assertThat(opts.getTransDir(), equalTo(new File(".")));
assertThat(opts.getSrcDir()).isEqualTo(new File("."));
assertThat(opts.getTransDir()).isEqualTo(new File("."));
}
@Test
@@ -107,11 +104,10 @@ public void optionTakesPrecedenceOverConfig() {
OptionsUtil.applyIncludesAndExcludesFromProjectConfig(opts, config);
// Then:
assertThat(opts.getSrcDir(), equalTo(new File("pot")));
assertThat(opts.getTransDir(), equalTo(new File(".")));
assertThat(opts.getIncludes(), Matchers.contains("*.properties"));
assertThat(opts.getExcludes(),
Matchers.contains("a.properties", "b.properties"));
assertThat(opts.getSrcDir()).isEqualTo(new File("pot"));
assertThat(opts.getTransDir()).isEqualTo(new File("."));
assertThat(opts.getIncludes()).contains("*.properties");
assertThat(opts.getExcludes()).contains("a.properties", "b.properties");
}
@Test
@@ -153,15 +149,15 @@ public void willNotFetchFromServerIfNoProjectConfigDefined() {
boolean result = OptionsUtil
.shouldFetchLocalesFromServer(Optional.empty(),
opts);
assertThat(result, equalTo(false));
assertThat(result).isFalse();
}
@Test
public void willFetchFromServerIfProjectConfigHasNoLocalesDefined() {
boolean result = OptionsUtil.shouldFetchLocalesFromServer(
Optional.of(new ZanataConfig()),
opts);
assertThat(result, equalTo(true));
assertThat(result).isTrue();
}
@Test
@@ -173,20 +169,20 @@ public void willNotFetchFromServerIfProjectConfigHasLocalesDefined() {
opts.setInteractiveMode(false);
boolean result = OptionsUtil.shouldFetchLocalesFromServer(
Optional.of(config), opts);
assertThat(result, equalTo(false));
assertThat(result).isFalse();
}
@Test
public void readProjectConfigWillReturnEmptyIfNoProjectConfigDefinedInOptions()
throws JAXBException {
assertThat(OptionsUtil.readProjectConfigFile(opts).isPresent(), equalTo(false));
assertThat(OptionsUtil.readProjectConfigFile(opts).isPresent()).isFalse();
}
@Test
public void readProjectConfigWillReturnEmptyIfProjectConfigDefinedInOptionsDoesNotExist()
throws JAXBException {
opts.setProjectConfig(new File("does not exist"));
assertThat(OptionsUtil.readProjectConfigFile(opts).isPresent(), equalTo(false));
assertThat(OptionsUtil.readProjectConfigFile(opts).isPresent()).isFalse();
}
@Test
@@ -202,8 +198,8 @@ public void readProjectConfigCanUnmarshalToZanataConfig() throws Exception {
Files.write(configFile.toPath(), configLines, Charsets.UTF_8);
opts.setProjectConfig(configFile);
assertThat(OptionsUtil.readProjectConfigFile(opts).isPresent(), equalTo(true));
assertThat(OptionsUtil.readProjectConfigFile(opts).get(), isA(ZanataConfig.class));
assertThat(OptionsUtil.readProjectConfigFile(opts).isPresent()).isTrue();
assertThat(OptionsUtil.readProjectConfigFile(opts).get())
.isInstanceOfAny(ZanataConfig.class);
}
}
Oops, something went wrong.

0 comments on commit c973f7d

Please sign in to comment.