TranslationKitStep extends BasePipelineStep { @Override protected Event handleTextUnit(Event event) { ITextUnit textUnit = event.getTextUnit(); TranslationKitTextUnit translationKitTextUnit = new TranslationKitTextUnit(); translationKitTextUnit.setTranslationKit(translationKitRepository.getOne(translationKitId)); Long textUnitId = Long.valueOf(textUnit.getId()); TMTextUnit tmTextUnit = tmTextUnitRepository.getOne(textUnitId); translationKitTextUnit.setTmTextUnit(tmTextUnit); wordCount += tmTextUnit.getWordCount(); translationKitTextUnit.setExportedTmTextUnitVariant(getTMTextUnitVariant(textUnit)); translationKitTextUnits.add(translationKitTextUnit); textUnit.setPreserveWhitespaces(true); return event; } TranslationKitStep(Long translationKitId); @Override String getName(); @Override String getDescription();  }
@Test public void testHandleTextUnit() { logger.debug("Ids for entities worked on"); Long translationKitId = 987654321L; Long tmTextUnitId = 654987321L; Long tmTextUnitVariantId = 123456789L; TMTextUnit tmTextUnit = new TMTextUnit(); tmTextUnit.setId(tmTextUnitId); tmTextUnit.setWordCount(1); logger.debug("State of the instance to be checked"); List<TranslationKitTextUnit> translationKitTextUnits = new ArrayList<>(); logger.debug("Create mocks"); TranslationKitRepository mockTranslationKitRepository = getJpaRepositoryMockForGetOne(TranslationKitRepository.class, TranslationKit.class, translationKitId); TMTextUnitVariantRepository mockTmTextUnitVariantRepository = getJpaRepositoryMockForGetOne(TMTextUnitVariantRepository.class, TMTextUnitVariant.class, tmTextUnitVariantId); TMTextUnitRepository mockTmTextUnitRepository = mock(TMTextUnitRepository.class); when(mockTmTextUnitRepository.getOne(tmTextUnitId)).thenReturn(tmTextUnit); logger.debug("Create instance to be tested, inject mocks and state"); TranslationKitStep translationKitStep = new TranslationKitStep(translationKitId); translationKitStep.textUnitDTOAnnotations = new TextUnitDTOAnnotations(); translationKitStep.translationKitRepository = mockTranslationKitRepository; translationKitStep.tmTextUnitRepository = mockTmTextUnitRepository; translationKitStep.tmTextUnitVariantRepository = mockTmTextUnitVariantRepository; translationKitStep.translationKitTextUnits = translationKitTextUnits; logger.debug("Build test input"); ITextUnit textUnit = new TextUnit(tmTextUnitId.toString()); TextUnitDTO textUnitDTO = new TextUnitDTO(); textUnitDTO.setTmTextUnitVariantId(tmTextUnitVariantId); textUnit.setAnnotation(new TextUnitDTOAnnotation(textUnitDTO)); Event event = new Event(EventType.TEXT_UNIT); event.setResource(textUnit); logger.debug("Test and assert"); Event result = translationKitStep.handleTextUnit(event); assertEquals("the input event should be returned", event, result); assertEquals("A TranslationKitTextUnit must be added", 1, translationKitTextUnits.size()); TranslationKitTextUnit translationKitTextUnit = translationKitTextUnits.get(0); assertEquals("translationKitId must match what was in the TextUnitDTO", translationKitId, translationKitTextUnit.getTranslationKit().getId()); assertEquals("tmTextUnitId must match what was in the TextUnitDTO", tmTextUnitId, translationKitTextUnit.getTmTextUnit().getId()); assertEquals("tmTextUnitVariantId of entites must match what was in the TextUnitDTO", tmTextUnitVariantId, translationKitTextUnit.getExportedTmTextUnitVariant().getId()); }