Skip to content

Commit

Permalink
add mapper test
Browse files Browse the repository at this point in the history
  • Loading branch information
doomedcat17 committed Jul 29, 2022
1 parent ad9d627 commit a35dd74
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public Translation translate(String sourceText, Language sourceLanguage, Languag
}
Translation translation = translationBodyMapper.map(response.body());
translation.setSourceText(sourceText);
translation.setRawData(response.body());
translation.setTargetLanguage(targetLanguage);
translation.setUri(uri);
return translation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public Translation map(String body) throws JsonProcessingException {
ArrayNode arrayNode = (ArrayNode) objectMapper.readTree(body);
translation.setTranslatedText(mapContent((ArrayNode) arrayNode.get(0)));
translation.setSourceLanguage(mapSourceLanguage(arrayNode));
translation.setRawData(body);
return translation;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.doomedcat17.opentranslator.translation.mapper;

import com.doomedcat17.opentranslator.language.Language;
import com.doomedcat17.opentranslator.translation.Translation;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.jupiter.api.Test;

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

class TranslationBodyMapperTest {

private TranslationBodyMapper translationBodyMapper = new TranslationBodyMapper();


@Test
void shouldMapBody() throws JsonProcessingException {
//given
String body = "[[[\"The facility was moved to Site 19 in 1993. \",\"Obiekt przeniesiony został do Ośrodka 19 w 1993 roku.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"Its origin has not been known so far. \",\"Jego pochodzenie dotychczas nie zostało poznane.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"SCP-173 is constructed of concrete and rebar and painted with Krylon brand spray paint. \",\"SCP-173 jest zbudowany z betonu i prętów zbrojeniowych oraz pomalowany farbą w spreju marki Krylon.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"SCP-173 is alive and extremely dangerous. \",\"SCP-173 jest żywy i ekstremalnie niebezpieczny.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"The subject cannot move while anyone is looking at it. \",\"Obiekt nie może się poruszać, kiedy ktokolwiek na niego patrzy.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"Always maintain eye contact with the subject. \",\"Z obiektem należy zawsze utrzymywać kontakt wzrokowy.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"Staff members admitted to containment containing SCP-173 are instructed to report before they blink. \",\"Członkowie personelu wpuszczani do przechowalni zawierającej SCP-173 są instruowani, by zgłaszać, zanim mrugną.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"The subject's attacks lead to the victim's neck twisting at the base of the skull or suffocating. \",\"Ataki obiektu prowadzą do skręcenia ofierze karku u podstawy czaszki lub jej uduszenia.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]],[\"In the event of an attack, personnel are to follow Class 4 hazardous object containment procedures.\",\"W przypadku ataku personel zobligowany jest zastosować się do procedur przechowawczych dla obiektów niebezpiecznych 4. klasy.\",null,null,3,null,null,[[]],[[[\"f5850fbc6fee2d714b8bd6523cfdad72\",\"pl_en_2020q2.md\"]]]]],null,\"pl\",null,null,[[\"Obiekt przeniesiony został do Ośrodka 19 w 1993 roku.\",null,[[\"The facility was moved to Site 19 in 1993.\",0,true,false,[3],null,[[3]]],[\"The facility was transferred to Site 19 in 1993.\",0,true,false,[8]]],[[0,53]],\"Obiekt przeniesiony został do Ośrodka 19 w 1993 roku.\",0,0],[\"Jego pochodzenie dotychczas nie zostało poznane.\",null,[[\"Its origin has not been known so far.\",0,true,false,[3],null,[[3]]],[\"Its origin has yet to be known.\",0,true,false,[8]]],[[0,48]],\"Jego pochodzenie dotychczas nie zostało poznane.\",0,0],[\"SCP-173 jest zbudowany z betonu i prętów zbrojeniowych oraz pomalowany farbą w spreju marki Krylon.\",null,[[\"SCP-173 is constructed of concrete and rebar and painted with Krylon brand spray paint.\",0,true,false,[3],null,[[3]]],[\"SCP-173 is constructed of concrete and rebar and painted with Krylon spray paint.\",0,true,false,[8]]],[[0,99]],\"SCP-173 jest zbudowany z betonu i prętów zbrojeniowych oraz pomalowany farbą w spreju marki Krylon.\",0,0],[\"SCP-173 jest żywy i ekstremalnie niebezpieczny.\",null,[[\"SCP-173 is alive and extremely dangerous.\",0,true,false,[3],null,[[3]]],[\"SCP-173 is alive and extremely hazardous.\",0,true,false,[8]]],[[0,47]],\"SCP-173 jest żywy i ekstremalnie niebezpieczny.\",0,0],[\"Obiekt nie może się poruszać, kiedy ktokolwiek na niego patrzy.\",null,[[\"The subject cannot move while anyone is looking at it.\",0,true,false,[3],null,[[3]]],[\"The subject cannot move while anyone is watching it.\",0,true,false,[8]]],[[0,63]],\"Obiekt nie może się poruszać, kiedy ktokolwiek na niego patrzy.\",0,0],[\"Z obiektem należy zawsze utrzymywać kontakt wzrokowy.\",null,[[\"Always maintain eye contact with the subject.\",0,true,false,[3],null,[[3]]],[\"Always keep eye contact with the object.\",0,true,false,[8]]],[[0,53]],\"Z obiektem należy zawsze utrzymywać kontakt wzrokowy.\",0,0],[\"Członkowie personelu wpuszczani do przechowalni zawierającej SCP-173 są instruowani, by zgłaszać, zanim mrugną.\",null,[[\"Staff members admitted to containment containing SCP-173 are instructed to report before they blink.\",0,true,false,[3],null,[[3]]],[\"Staff members admitted to containment of SCP-173 are instructed to report before they blink.\",0,true,false,[8]]],[[0,111]],\"Członkowie personelu wpuszczani do przechowalni zawierającej SCP-173 są instruowani, by zgłaszać, zanim mrugną.\",0,0],[\"Ataki obiektu prowadzą do skręcenia ofierze karku u podstawy czaszki lub jej uduszenia.\",null,[[\"The subject's attacks lead to the victim's neck twisting at the base of the skull or suffocating.\",0,true,false,[3],null,[[3]]],[\"The subject's attacks lead to the victim's neck twisting at the base of the skull or suffocating them.\",0,true,false,[8]]],[[0,87]],\"Ataki obiektu prowadzą do skręcenia ofierze karku u podstawy czaszki lub jej uduszenia.\",0,0],[\"W przypadku ataku personel zobligowany jest zastosować się do procedur przechowawczych dla obiektów niebezpiecznych 4. klasy.\",null,[[\"In the event of an attack, personnel are to follow Class 4 hazardous object containment procedures.\",0,true,false,[3],null,[[3]]],[\"In the event of an attack, personnel must follow Class 4 hazardous object containment procedures.\",0,true,false,[8]]],[[0,125]],\"W przypadku ataku personel zobligowany jest zastosować się do procedur przechowawczych dla obiektów niebezpiecznych 4. klasy.\",0,0]],1,[],[[\"pl\"],null,[1],[\"pl\"]]]";
String expectedText = "The facility was moved to Site 19 in 1993. Its origin has not been known so far. SCP-173 is constructed of concrete and rebar and painted with Krylon brand spray paint. SCP-173 is alive and extremely dangerous. The subject cannot move while anyone is looking at it. Always maintain eye contact with the subject. Staff members admitted to containment containing SCP-173 are instructed to report before they blink. The subject's attacks lead to the victim's neck twisting at the base of the skull or suffocating. In the event of an attack, personnel are to follow Class 4 hazardous object containment procedures.";
//when
Translation translation = translationBodyMapper.map(body);

//then
assertEquals(Language.POLISH, translation.getSourceLanguage());
assertEquals(body, translation.getRawData());
assertEquals(expectedText, translation.getTranslatedText());
}

}

0 comments on commit a35dd74

Please sign in to comment.