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

test: improve 'report' package code coverage #244

Merged
Merged
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
@@ -1,6 +1,5 @@
package com.crowdin.client.reports.model;

import com.crowdin.client.core.model.EnumConverter;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand Down Expand Up @@ -70,29 +69,4 @@ public static class TranslateIndividualRate {
private List<String> languageIdsTo;
private List<TranslateRegularRate> rates;
}

public enum Mode implements EnumConverter<Mode> {

NO_MATCH("no_match"), PERFECT("perfect"), OPTION_100("100"), OPTION_99_95("99-95"), OPTION_94_90("94-90"), OPTION_89_80("89-80");

private final String val;

Mode(String val) {
this.val = val;
}

public static Mode from(String value) {
for (Mode mode : Mode.values()) {
if (mode.val.equals(value)) {
return mode;
}
}
return null;
}

@Override
public String to(Mode v) {
return v.val;
}
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/crowdin/client/reports/model/Mode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.crowdin.client.reports.model;

import com.crowdin.client.core.model.EnumConverter;

public enum Mode implements EnumConverter<Mode> {

NO_MATCH("no_match"),
PERFECT("perfect"),
OPTION_100("100"),
OPTION_99_95("99-95"),
OPTION_94_90("94-90"),
OPTION_89_80("89-80");

private final String val;

Mode(String val) {
this.val = val;
}

public static Mode from(String value) {
for (Mode mode : Mode.values()) {
if (mode.val.equals(value)) {
return mode;
}
}
return null;
}

@Override
public String to(Mode v) {
return v.val;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

@Data
public class ReportStatusResponseObject {

private ReportStatus data;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.crowdin.client.reports.model;

import com.crowdin.client.core.model.EnumConverter;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -19,7 +18,7 @@ public static class Schema {

private Unit unit;
private Currency currency;
private GroupBy groupBy;
private GroupingParameter groupBy;
private String languageId;
private ReportsFormat format;
private List<StepType> stepTypes;
Expand Down Expand Up @@ -70,43 +69,4 @@ public static class TranslateIndividualRate {
private List<String> languageIdsTo;
private List<TranslateRegularRate> rates;
}

public enum Mode implements EnumConverter<Mode> {

NO_MATCH("no_match"), PERFECT("perfect"), OPTION_100("100"), OPTION_99_95("99-95"), OPTION_94_90("94-90"), OPTION_89_80("89-80");

private final String val;

Mode(String val) {
this.val = val;
}

public static Mode from(String value) {
for (Mode mode : Mode.values()) {
if (mode.val.equals(value)) {
return mode;
}
}
return null;
}

@Override
public String to(Mode v) {
return v.val;
}
}

public enum GroupBy implements EnumConverter<GroupBy> {

USER, LANGUAGE;

public static GroupBy from(String value) {
return GroupBy.valueOf(value.toUpperCase());
}

@Override
public String to(GroupBy v) {
return v.name().toLowerCase();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class Schema {

private Unit unit;
private Currency currency;
private GroupBy groupBy;
private GroupingParameter groupBy;
private String languageId;
private ReportsFormat format;
private List<StepType> stepTypes;
Expand Down Expand Up @@ -84,18 +84,4 @@ public String to(Mode v) {
return v.name().toLowerCase();
}
}

public enum GroupBy implements EnumConverter<GroupBy> {

USER, LANGUAGE;

public static GroupBy from(String value) {
return GroupBy.valueOf(value.toUpperCase());
}

@Override
public String to(GroupBy v) {
return v.name().toLowerCase();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.crowdin.client.reports.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class CostEstimateFuzzyModeGenerateReportRequestTest {

@Test
void from() {
Mode response = Mode.from("perfect");
assertEquals(Mode.PERFECT, response);

Mode response1 = Mode.from("100");
assertEquals(Mode.OPTION_100, response1);

Mode response2 = Mode.from("99-95");
assertEquals(Mode.OPTION_99_95, response2);

Mode response3 = Mode.from("94-90");
assertEquals(Mode.OPTION_94_90, response3);

Mode response4 = Mode.from("89-80");
assertEquals(Mode.OPTION_89_80, response4);

Mode response5 = Mode.from("no_match");
assertEquals(Mode.NO_MATCH, response5);

Mode response6 = Mode.from("do_not_match");
assertNull(response6);

}

@Test
void to() {
Object response = (Mode.PERFECT).to(Mode.PERFECT);
assertEquals(response, "perfect");

Object response1 = (Mode.NO_MATCH).to(Mode.NO_MATCH);
assertEquals(response1, "no_match");

Object response2 = (Mode.OPTION_100).to(Mode.OPTION_100);
assertEquals(response2, "100");

Object response3 = (Mode.OPTION_89_80).to(Mode.OPTION_89_80);
assertEquals(response3, "89-80");

Object response4 = (Mode.OPTION_94_90).to(Mode.OPTION_94_90);
assertEquals(response4, "94-90");

Object response5 = (Mode.OPTION_99_95).to(Mode.OPTION_99_95);
assertEquals(response5, "99-95");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.crowdin.client.reports.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class GroupingParameterTest {

@Test
void from() {
GroupingParameter response = GroupingParameter.from("user");
assertEquals(GroupingParameter.USER, response);

GroupingParameter response1 = GroupingParameter.from("language");
assertEquals(GroupingParameter.LANGUAGE, response1);
}

@Test
void to() {
Object response = (GroupingParameter.USER).to(GroupingParameter.USER);
assertEquals(response, "user");

Object response1 = (GroupingParameter.LANGUAGE).to(GroupingParameter.LANGUAGE);
assertEquals(response1, "language");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.crowdin.client.reports.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class LabelIncludeTypeTest {

@Test
void from() {
LabelIncludeType response = LabelIncludeType.from("strings_with_label");
assertEquals(LabelIncludeType.STRINGS_WITH_LABEL, response);

LabelIncludeType response1 = LabelIncludeType.from("strings_without_label");
assertEquals(LabelIncludeType.STRINGS_WITHOUT_LABEL, response1);
}

@Test
void to() {
Object response = (LabelIncludeType.STRINGS_WITH_LABEL).to(LabelIncludeType.STRINGS_WITH_LABEL);
assertEquals(response, "strings_with_label");

Object response1 = (LabelIncludeType.STRINGS_WITHOUT_LABEL).to(LabelIncludeType.STRINGS_WITHOUT_LABEL);
assertEquals(response1, "strings_without_label");
}
}
42 changes: 42 additions & 0 deletions src/test/java/com/crowdin/client/reports/model/MatchTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.crowdin.client.reports.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class MatchTypeTest {

@Test
void from() {
MatchType response = MatchType.from("perfect");
assertEquals(MatchType.PERFECT, response);

MatchType response1 = MatchType.from("100");
assertEquals(MatchType.OPTION_100, response1);

MatchType response2 = MatchType.from("99-82");
assertEquals(MatchType.OPTION_99_82, response2);

MatchType response3 = MatchType.from("81-60");
assertEquals(MatchType.OPTION_81_60, response3);

MatchType response4 = MatchType.from("do_not_match");
assertNull(response4);

}

@Test
void to() {
Object response = (MatchType.PERFECT).to(MatchType.PERFECT);
assertEquals(response, "perfect");

Object response1 = (MatchType.OPTION_100).to(MatchType.OPTION_100);
assertEquals(response1, "100");

Object response2 = (MatchType.OPTION_99_82).to(MatchType.OPTION_99_82);
assertEquals(response2, "99-82");

Object response3 = (MatchType.OPTION_81_60).to(MatchType.OPTION_81_60);
assertEquals(response3, "81-60");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.crowdin.client.reports.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class Reports2FormatTest {

@Test
void from() {
Reports2Format response = Reports2Format.from("xlsx");
assertEquals(Reports2Format.XLSX, response);

Reports2Format response1 = Reports2Format.from("csv");
assertEquals(Reports2Format.CSV, response1);

}

@Test
void to() {
Object response = (Reports2Format.XLSX).to(Reports2Format.XLSX);
assertEquals(response, "xlsx");

Object response1 = (Reports2Format.CSV).to(Reports2Format.CSV);
assertEquals(response1, "csv");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.crowdin.client.reports.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class TranslationCostGenerateReportRequestTest {

@Test
void from() {

TranslationCostGenerateReportRequest.Mode response = TranslationCostGenerateReportRequest.Mode.from("no_match");
assertEquals(TranslationCostGenerateReportRequest.Mode.NO_MATCH, response);

TranslationCostGenerateReportRequest.Mode response2 = TranslationCostGenerateReportRequest.Mode.from("tm_match");
assertEquals(TranslationCostGenerateReportRequest.Mode.TM_MATCH, response2);

}

@Test
void to() {
Object response = (TranslationCostGenerateReportRequest.Mode.TM_MATCH).to(TranslationCostGenerateReportRequest.Mode.TM_MATCH);
assertEquals(response, "tm_match");

Object response1 = (TranslationCostGenerateReportRequest.Mode.NO_MATCH).to(TranslationCostGenerateReportRequest.Mode.NO_MATCH);
assertEquals(response1, "no_match");
}

}
Loading