bossenti commented on code in PR #2355: URL: https://github.com/apache/streampipes/pull/2355#discussion_r1433667591
########## streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/locales/LabelGeneratorTest.java: ########## @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.streampipes.extensions.management.locales; + +import org.apache.streampipes.model.base.NamedStreamPipesEntity; + +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +public class LabelGeneratorTest { + + private static final String TEST_APP_ID = "test-app-id"; + + @Test + public void getElementDescriptionThrowExceptiojn() { + var labelGenerator = getLabelGeneratorWithoutLocalesFile(); + assertThrows(IOException.class, labelGenerator::getElementDescription); + } + + @Test + public void getElementDescriptionReturnsCorrectDescription() throws IOException { + var expectedDescription = "test-description"; + var properties = getProperties(LabelGenerator.DESCRIPTION, expectedDescription); + + var labelGenerator = getLabelGeneratorWithProperties(properties); + + assertEquals(expectedDescription, labelGenerator.getElementDescription()); + } + + @Test + public void getElementTitleThrowExceptiojn() { + var labelGenerator = getLabelGeneratorWithoutLocalesFile(); + assertThrows(IOException.class, labelGenerator::getElementTitle); + } + + @Test + public void getElementTitleReturnsCorrectDescription() throws IOException { + var expectedTitle = "test-title"; + var properties = getProperties(LabelGenerator.TITLE, expectedTitle); + + var labelGenerator = getLabelGeneratorWithProperties(properties); + + assertEquals(expectedTitle, labelGenerator.getElementTitle()); + } + + + private LabelGenerator getLabelGeneratorWithoutLocalesFile() { + var mockDescription = Mockito.mock(NamedStreamPipesEntity.class); + when(mockDescription.getAppId()).thenReturn(TEST_APP_ID); + + var labelGenerator = new LabelGenerator(mockDescription); + var mockGenerator = spy(labelGenerator); Review Comment: `mockedLabelGenerator` or `labelGeneratorMock` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
