Skip to content
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
Expand Up @@ -7,6 +7,7 @@
*/
public enum IntegrityCheckerType {
MESSAGE_FORMAT,
FLUENT,
MESSAGE_FORMAT_DOUBLE_BRACES,
PRINTF_LIKE,
PRINTF_LIKE_IGNORE_PERCENTAGE_AFTER_BRACKETS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.box.l10n.mojito.rest.entity;

import static org.junit.Assert.assertEquals;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

/**
* The restclient enum is deserialized from server JSON by name. A missing constant (historically
* {@code FLUENT}) makes {@code repo-view} / {@code repo-update} fail for that checker.
*/
public class IntegrityCheckerTypeTest {

private final ObjectMapper objectMapper = new ObjectMapper();

@Test
public void everyTypeDeserializesFromItsJsonName() throws Exception {
for (IntegrityCheckerType type : IntegrityCheckerType.values()) {
IntegrityCheckerType parsed =
objectMapper.readValue("\"" + type.name() + "\"", IntegrityCheckerType.class);
assertEquals(type.name(), type, parsed);
}
}

@Test
public void everyTypeDeserializesInACheckerPayload() throws Exception {
for (IntegrityCheckerType type : IntegrityCheckerType.values()) {
String json =
"{\"assetExtension\":\"ftl\",\"integrityCheckerType\":\"" + type.name() + "\"}";
IntegrityChecker checker = objectMapper.readValue(json, IntegrityChecker.class);
assertEquals(type.name(), "ftl", checker.getAssetExtension());
assertEquals(type.name(), type, checker.getIntegrityCheckerType());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.box.l10n.mojito.service.assetintegritychecker.integritychecker;

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

import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;

/**
* Restclient {@code IntegrityCheckerType} is a name-only mirror of this server enum. Jackson
* deserializes by name, not ordinal — ordinals already diverge ({@code SIMPLE_PRINTF_LIKE}).
*/
public class IntegrityCheckerTypeTest {

@Test
public void restclientEnumHasTheSameNameSetAsTheServer() {
Set<String> serverNames =
Arrays.stream(IntegrityCheckerType.values()).map(Enum::name).collect(Collectors.toSet());
Set<String> restclientNames =
Arrays.stream(com.box.l10n.mojito.rest.entity.IntegrityCheckerType.values())
.map(Enum::name)
.collect(Collectors.toSet());

Set<String> onlyOnServer = new TreeSet<>(serverNames);
onlyOnServer.removeAll(restclientNames);
Set<String> onlyOnRestclient = new TreeSet<>(restclientNames);
onlyOnRestclient.removeAll(serverNames);

assertEquals(Set.of(), onlyOnServer, "on server but missing from restclient");
assertEquals(Set.of(), onlyOnRestclient, "on restclient but missing from server");
}
}
Loading