Commit 9b566ecc authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Added bunch of finals and removed an unnecessary test function

parent 36eea625
Pipeline #305 failed with stage
in 16 seconds
......@@ -66,8 +66,8 @@ public class JcrNodeToNodeConverterTest {
@Test
public void testNodePath() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
when(propertyIterator.hasNext()).thenReturn(false);
when(nodeIterator.hasNext()).thenReturn(false);
......@@ -76,16 +76,16 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertEquals("/test", result.getPath());
}
@Test
public void testSingleProperty() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
Property property = mock(Property.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final Property property = mock(Property.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
when(property.getName()).thenReturn("jeff:testProperty");
when(property.getType()).thenReturn(PropertyType.STRING);
......@@ -100,12 +100,12 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getProperties());
Assert.assertEquals(1, result.getProperties().size());
NodeProperty nodeProperty = result.getProperties().iterator().next();
final NodeProperty nodeProperty = result.getProperties().iterator().next();
Assert.assertEquals("jeff:testProperty", nodeProperty.getName());
Assert.assertEquals("testValue", nodeProperty.getValue());
Assert.assertEquals(PropertyType.nameFromValue(PropertyType.STRING), nodeProperty.getType());
......@@ -113,10 +113,10 @@ public class JcrNodeToNodeConverterTest {
@Test
public void testMultipleProperty() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
Property property = mock(Property.class);
Value value = mock(Value.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final Property property = mock(Property.class);
final Value value = mock(Value.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
when(property.getName()).thenReturn("jeff:testProperty");
when(property.getType()).thenReturn(PropertyType.STRING);
......@@ -133,12 +133,12 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getProperties());
Assert.assertEquals(1, result.getProperties().size());
NodeProperty nodeProperty = result.getProperties().iterator().next();
final NodeProperty nodeProperty = result.getProperties().iterator().next();
Assert.assertEquals("jeff:testProperty", nodeProperty.getName());
Assert.assertEquals(2, nodeProperty.getValues().size());
Assert.assertEquals(PropertyType.nameFromValue(PropertyType.STRING), nodeProperty.getType());
......@@ -146,11 +146,11 @@ public class JcrNodeToNodeConverterTest {
@Test
public void testBinaryAsMultipleProperty() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
Property property = mock(Property.class);
Value value = mock(Value.class);
Value binaryValue = mock(Value.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final Property property = mock(Property.class);
final Value value = mock(Value.class);
final Value binaryValue = mock(Value.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
when(property.getName()).thenReturn("jeff:testProperty");
when(property.getType()).thenReturn(PropertyType.STRING);
......@@ -168,12 +168,12 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getProperties());
Assert.assertEquals(1, result.getProperties().size());
NodeProperty nodeProperty = result.getProperties().iterator().next();
final NodeProperty nodeProperty = result.getProperties().iterator().next();
Assert.assertEquals("jeff:testProperty", nodeProperty.getName());
Assert.assertEquals(1, nodeProperty.getValues().size());
Assert.assertEquals(PropertyType.nameFromValue(PropertyType.STRING), nodeProperty.getType());
......@@ -181,10 +181,10 @@ public class JcrNodeToNodeConverterTest {
@Test
public void testBinaryProperty() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
Property property = mock(Property.class);
Value binaryValue = mock(Value.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final Property property = mock(Property.class);
final Value binaryValue = mock(Value.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
when(property.getName()).thenReturn("jeff:testProperty");
when(property.getType()).thenReturn(PropertyType.STRING);
......@@ -201,12 +201,12 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getProperties());
Assert.assertEquals(1, result.getProperties().size());
NodeProperty nodeProperty = result.getProperties().iterator().next();
final NodeProperty nodeProperty = result.getProperties().iterator().next();
Assert.assertEquals("jeff:testProperty", nodeProperty.getName());
Assert.assertEquals(1, nodeProperty.getValues().size());
Assert.assertNull(nodeProperty.getValue());
......@@ -216,9 +216,9 @@ public class JcrNodeToNodeConverterTest {
@Test
public void testChildNode() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
Node childNode = mock(Node.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
final Node childNode = mock(Node.class);
when(propertyIterator.hasNext()).thenReturn(false);
when(nodeIterator.hasNext()).thenReturn(true, false);
......@@ -229,7 +229,7 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getChildren());
......@@ -239,10 +239,10 @@ public class JcrNodeToNodeConverterTest {
@Test
public void testChildNodeFilter() throws Exception {
PropertyIterator propertyIterator = mock(PropertyIterator.class);
NodeIterator nodeIterator = mock(NodeIterator.class);
Node childNode = mock(Node.class);
Node childNode2 = mock(Node.class);
final PropertyIterator propertyIterator = mock(PropertyIterator.class);
final NodeIterator nodeIterator = mock(NodeIterator.class);
final Node childNode = mock(Node.class);
final Node childNode2 = mock(Node.class);
when(propertyIterator.hasNext()).thenReturn(false);
when(nodeIterator.hasNext()).thenReturn(true, true, false);
......@@ -254,7 +254,7 @@ public class JcrNodeToNodeConverterTest {
when(node.getProperties()).thenReturn(propertyIterator);
when(node.getNodes()).thenReturn(nodeIterator);
com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
final com.jeff_cms.jeff.model.Node result = conversionService.convert(node, com.jeff_cms.jeff.model.Node.class);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getChildren());
......
......@@ -58,10 +58,10 @@ public class ImageServiceTest {
public void testConversion() throws Exception {
final InputStream inputStream = new ClassPathResource("testBinary.png").getInputStream();
InputStream result = imageService.resize(inputStream, 0, 0, MediaType.IMAGE_JPEG_VALUE, false);
final InputStream result = imageService.resize(inputStream, 0, 0, MediaType.IMAGE_JPEG_VALUE, false);
Assert.assertNotNull(result);
ImageReader reader = getImageReader(result);
final ImageReader reader = getImageReader(result);
Assert.assertNotNull(reader);
Assert.assertEquals("JPEG", reader.getFormatName().toUpperCase());
Assert.assertEquals(1440, reader.getWidth(0));
......@@ -72,10 +72,10 @@ public class ImageServiceTest {
public void testScalingWithAspectRatioWidth() throws Exception {
final InputStream inputStream = new ClassPathResource("testBinary.png").getInputStream();
InputStream result = imageService.resize(inputStream, 720, 0, MediaType.IMAGE_PNG_VALUE, false);
final InputStream result = imageService.resize(inputStream, 720, 0, MediaType.IMAGE_PNG_VALUE, false);
Assert.assertNotNull(result);
ImageReader reader = getImageReader(result);
final ImageReader reader = getImageReader(result);
Assert.assertNotNull(reader);
Assert.assertEquals("PNG", reader.getFormatName().toUpperCase());
Assert.assertEquals(720, reader.getWidth(0));
......@@ -86,10 +86,10 @@ public class ImageServiceTest {
public void testScalingWithAspectRatioHeight() throws Exception {
final InputStream inputStream = new ClassPathResource("testBinary.png").getInputStream();
InputStream result = imageService.resize(inputStream, 0, 450, MediaType.IMAGE_PNG_VALUE, false);
final InputStream result = imageService.resize(inputStream, 0, 450, MediaType.IMAGE_PNG_VALUE, false);
Assert.assertNotNull(result);
ImageReader reader = getImageReader(result);
final ImageReader reader = getImageReader(result);
Assert.assertNotNull(reader);
Assert.assertEquals("PNG", reader.getFormatName().toUpperCase());
Assert.assertEquals(720, reader.getWidth(0));
......@@ -100,24 +100,24 @@ public class ImageServiceTest {
public void testScaling() throws Exception {
final InputStream inputStream = new ClassPathResource("testBinary.png").getInputStream();
InputStream result = imageService.resize(inputStream, 800, 600, MediaType.IMAGE_PNG_VALUE, false);
final InputStream result = imageService.resize(inputStream, 800, 600, MediaType.IMAGE_PNG_VALUE, false);
Assert.assertNotNull(result);
ImageReader reader = getImageReader(result);
final ImageReader reader = getImageReader(result);
Assert.assertNotNull(reader);
Assert.assertEquals("PNG", reader.getFormatName().toUpperCase());
Assert.assertEquals(800, reader.getWidth(0));
Assert.assertEquals(600, reader.getHeight(0));
}
private ImageReader getImageReader(InputStream inputStream) {
private ImageReader getImageReader(final InputStream inputStream) {
try {
ImageInputStream iis = ImageIO.createImageInputStream(inputStream);
Iterator iter = ImageIO.getImageReaders(iis);
final ImageInputStream iis = ImageIO.createImageInputStream(inputStream);
final Iterator iter = ImageIO.getImageReaders(iis);
if (!iter.hasNext()) {
return null;
}
ImageReader reader = (ImageReader) iter.next();
final ImageReader reader = (ImageReader) iter.next();
reader.setInput(iis);
return reader;
......
......@@ -102,9 +102,9 @@ public class PublishServiceTest {
request.getNodes().add(node);
CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
final CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
assertNotNull(response);
PublishResponse publishResponse = response.get();
final PublishResponse publishResponse = response.get();
assertNotNull(publishResponse);
assertNotNull(publishResponse.getUnsuccessful());
......@@ -140,9 +140,9 @@ public class PublishServiceTest {
request.getNodes().add(getTestNode());
}
CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
final CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
assertNotNull(response);
PublishResponse publishResponse = response.get();
final PublishResponse publishResponse = response.get();
assertNotNull(publishResponse);
assertNotNull(publishResponse.getUnsuccessful());
......@@ -182,9 +182,9 @@ public class PublishServiceTest {
request.getNodes().add(getTestNode());
}
CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
final CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
assertNotNull(response);
PublishResponse publishResponse = response.get();
final PublishResponse publishResponse = response.get();
assertNotNull(publishResponse);
assertNotNull(publishResponse.getUnsuccessful());
......@@ -228,9 +228,9 @@ public class PublishServiceTest {
request.getNodes().add(getTestNode());
}
CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
final CompletableFuture<PublishResponse> response = publishService.performPublishCall("test", request);
assertNotNull(response);
PublishResponse publishResponse = response.get();
final PublishResponse publishResponse = response.get();
assertNotNull(publishResponse);
assertNotNull(publishResponse.getUnsuccessful());
......
......@@ -26,12 +26,10 @@ package com.jeff_cms.jeff.node.utils;
import com.jeff_cms.jeff.model.Node;
import com.jeff_cms.jeff.model.NodeProperty;
import org.mockito.Mockito;
import javax.jcr.PropertyType;
import java.util.Collections;
import java.util.UUID;
import java.util.function.Consumer;
import static com.jeff_cms.jeff.node.Constants.PROPERTY_CHECKSUM;
......@@ -58,20 +56,5 @@ public class TestUtils {
node.getProperties().add(nodeVersionProperty);
return node;
}
/**
* Create a mock JCR node for testing purposes.
* @param nodeSetup Function to set up the node after creation.
* @return JCR node
*/
public static javax.jcr.Node getTestJcrNode(Consumer<javax.jcr.Node> nodeSetup) {
javax.jcr.Node node = Mockito.mock(javax.jcr.Node.class);
nodeSetup.accept(node);
return node;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment