mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 03:53:07 +00:00
Fixes to various errorprone warnings in tests
This commit is contained in:
@@ -14,7 +14,9 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -85,7 +87,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
log.error("SQL Error in init", ex);
|
||||
fail("SQL Error in init: " + ex.getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("IO Error in init", e);
|
||||
fail("IO Error in init: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +122,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
||||
assertEquals("Pdf", urlSplitted[urlSplitted.length - 1]);
|
||||
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||
assertEquals("Pdf", urlSplitted.get(urlSplitted.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,8 +157,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
||||
assertEquals("size9", urlSplitted[urlSplitted.length - 1]);
|
||||
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||
assertEquals("size9", urlSplitted.get(urlSplitted.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,8 +192,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
||||
assertEquals("first", urlSplitted[urlSplitted.length - 1]);
|
||||
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||
assertEquals("first", urlSplitted.get(urlSplitted.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,8 +228,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
||||
assertEquals("primary", urlSplitted[urlSplitted.length - 1]);
|
||||
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||
assertEquals("primary", urlSplitted.get(urlSplitted.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,8 +264,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
||||
assertEquals("large", urlSplitted[urlSplitted.length - 1]);
|
||||
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||
assertEquals("large", urlSplitted.get(urlSplitted.size() - 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +288,7 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
@Test
|
||||
public void testGetPDFURLWithNoBitstreams() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL");
|
||||
ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL");
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
@@ -319,8 +322,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
context.restoreAuthSystemState();
|
||||
context.commit();
|
||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
||||
assertEquals("small", urlSplitted[urlSplitted.length - 1]);
|
||||
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||
assertEquals("small", urlSplitted.get(urlSplitted.size() - 1));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -334,12 +337,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
community = context.reloadEntity(community);
|
||||
ContentServiceFactory.getInstance().getCommunityService().delete(context, community);
|
||||
community = null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AuthorizeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Error occurred in destroy()", e);
|
||||
}
|
||||
it = null;
|
||||
super.destroy();
|
||||
|
@@ -363,7 +363,7 @@ public class BundleTest extends AbstractDSpaceObjectTest {
|
||||
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
|
||||
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.create(context, b, new FileInputStream(f));
|
||||
bitstreamService.create(context, b, new FileInputStream(f));
|
||||
fail("Exception should be thrown");
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ public class BundleTest extends AbstractDSpaceObjectTest {
|
||||
|
||||
int assetstore = 0; //default assetstore
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.register(context, b, assetstore, f.getAbsolutePath());
|
||||
bitstreamService.register(context, b, assetstore, f.getAbsolutePath());
|
||||
fail("Exception should be thrown");
|
||||
}
|
||||
|
||||
|
@@ -196,7 +196,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
|
||||
// test creating collection with a specified handle which IS already in use
|
||||
// This should throw an exception
|
||||
Collection created = collectionService.create(context, owningCommunity, inUseHandle);
|
||||
collectionService.create(context, owningCommunity, inUseHandle);
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
@@ -291,7 +291,6 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
String itext = "introductory text";
|
||||
String copy = "copyright declaration";
|
||||
String sidebar = "side bar text";
|
||||
String tempItem = "3";
|
||||
String provDesc = "provenance description";
|
||||
String license = "license text";
|
||||
|
||||
@@ -370,7 +369,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testSetLogoNoAuth() throws Exception {
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream logo = collectionService.setLogo(context, collection, new FileInputStream(f));
|
||||
collectionService.setLogo(context, collection, new FileInputStream(f));
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
@@ -393,7 +392,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testCreateWorkflowGroupNoAuth() throws Exception {
|
||||
int step = 1;
|
||||
Group result = collectionService.createWorkflowGroup(context, collection, step);
|
||||
collectionService.createWorkflowGroup(context, collection, step);
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
@@ -461,7 +460,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
*/
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testCreateSubmittersNoAuth() throws Exception {
|
||||
Group result = collectionService.createSubmitters(context, collection);
|
||||
collectionService.createSubmitters(context, collection);
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
@@ -511,7 +510,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
||||
*/
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testCreateAdministratorsNoAuth() throws Exception {
|
||||
Group result = collectionService.createAdministrators(context, collection);
|
||||
collectionService.createAdministrators(context, collection);
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
|
@@ -28,11 +28,6 @@ import org.junit.Test;
|
||||
* @author pvillega
|
||||
*/
|
||||
public class DCDateTest {
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(DCDateTest.class);
|
||||
|
||||
/**
|
||||
* Object to use in the tests
|
||||
*/
|
||||
|
@@ -13,11 +13,9 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.content.dao.RelationshipTypeDAO;
|
||||
import org.dspace.content.service.EntityTypeService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.content.service.RelationshipService;
|
||||
@@ -60,10 +58,8 @@ public class EntityServiceImplTest {
|
||||
public void testfindByItemId() throws Exception {
|
||||
// Declare objects utilized in unit test
|
||||
Item item = mock(Item.class);
|
||||
List<Relationship> relationshipList = new ArrayList<>();
|
||||
Relationship relationship = mock(Relationship.class);
|
||||
relationship.setId(9);
|
||||
relationshipList.add(relationship);
|
||||
|
||||
// Mock the state of objects utilized in findByItemId() to meet the success criteria of an invocation
|
||||
when(itemService.find(any(), any())).thenReturn(item);
|
||||
@@ -79,10 +75,6 @@ public class EntityServiceImplTest {
|
||||
// Declare objects utilized in unit test
|
||||
Entity entity = mock(Entity.class);
|
||||
EntityTypeService entityTypeService = mock(EntityTypeService.class);
|
||||
Item item = mock(Item.class);
|
||||
List<MetadataValue> list = new ArrayList<>();
|
||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
||||
list.add(metadataValue);
|
||||
EntityType entityType = entityTypeService.findByEntityType(context, "testType");
|
||||
|
||||
// The returned EntityType should equal our defined entityType case
|
||||
@@ -151,11 +143,7 @@ public class EntityServiceImplTest {
|
||||
@Test
|
||||
public void testGetAllRelationshipTypes() throws Exception {
|
||||
// Declare objects utilized for this test
|
||||
List<MetadataValue> list = new ArrayList<>();
|
||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
||||
list.add(metadataValue);
|
||||
Item item = mock(Item.class);
|
||||
RelationshipTypeDAO relationshipTypeDAO = mock(RelationshipTypeDAO.class);
|
||||
Entity entity = mock(Entity.class);
|
||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||
relationshipType.setLeftType(leftType);
|
||||
@@ -185,7 +173,7 @@ public class EntityServiceImplTest {
|
||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||
|
||||
// Currently this unit test will only test one case with one relationshipType
|
||||
List<RelationshipType> relationshipTypeList = new LinkedList<>();
|
||||
List<RelationshipType> relationshipTypeList = new ArrayList<>();
|
||||
relationshipTypeList.add(relationshipType);
|
||||
List<MetadataValue> metsList = new ArrayList<>();
|
||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
||||
@@ -213,7 +201,7 @@ public class EntityServiceImplTest {
|
||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||
|
||||
// Currently this unit test will only test one case with one relationshipType
|
||||
List<RelationshipType> relationshipTypeList = new LinkedList<>();
|
||||
List<RelationshipType> relationshipTypeList = new ArrayList<>();
|
||||
relationshipTypeList.add(relationshipType);
|
||||
List<MetadataValue> metsList = new ArrayList<>();
|
||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
||||
@@ -236,7 +224,7 @@ public class EntityServiceImplTest {
|
||||
@Test
|
||||
public void testGetRelationshipTypesByTypeName() throws Exception {
|
||||
// Declare objects utilized in unit test
|
||||
List<RelationshipType> list = new LinkedList<>();
|
||||
List<RelationshipType> list = new ArrayList<>();
|
||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||
list.add(relationshipType);
|
||||
|
||||
|
@@ -16,7 +16,6 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.AbstractIntegrationTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
@@ -37,11 +36,6 @@ import org.junit.Test;
|
||||
* @author pvillega
|
||||
*/
|
||||
public class ITMetadata extends AbstractIntegrationTest {
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ITMetadata.class);
|
||||
|
||||
|
||||
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||
|
@@ -132,8 +132,8 @@ public class ItemComparatorTest extends AbstractUnitTest {
|
||||
*/
|
||||
@Test
|
||||
public void testCompare() throws SQLException {
|
||||
int result = 0;
|
||||
ItemComparator ic = null;
|
||||
int result;
|
||||
ItemComparator ic;
|
||||
|
||||
//one of the tiems has no value
|
||||
ic = new ItemComparator("test", "one", Item.ANY, true);
|
||||
@@ -246,7 +246,7 @@ public class ItemComparatorTest extends AbstractUnitTest {
|
||||
@SuppressWarnings( {"ObjectEqualsNull", "IncompatibleEquals"})
|
||||
public void testEquals() {
|
||||
ItemComparator ic = new ItemComparator("test", "one", Item.ANY, true);
|
||||
ItemComparator target = null;
|
||||
ItemComparator target;
|
||||
|
||||
assertFalse("testEquals 0", ic.equals(null));
|
||||
assertFalse("testEquals 1", ic.equals("test one"));
|
||||
|
@@ -41,7 +41,6 @@ import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.BitstreamFormatService;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.content.service.MetadataSchemaService;
|
||||
import org.dspace.core.Constants;
|
||||
@@ -76,8 +75,6 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
.getBitstreamFormatService();
|
||||
private MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||
|
||||
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||
|
||||
private Collection collection;
|
||||
private Community owningCommunity;
|
||||
|
||||
@@ -839,7 +836,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testCreateBundleNoAuth() throws Exception {
|
||||
String name = "bundle";
|
||||
Bundle created = bundleService.create(context, it, name);
|
||||
bundleService.create(context, it, name);
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
@@ -941,7 +938,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
public void testCreateSingleBitstream_InputStream_StringNoAuth() throws Exception {
|
||||
String name = "new bundle";
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it, name);
|
||||
itemService.createSingleBitstream(context, new FileInputStream(f), it, name);
|
||||
fail("Exception expected");
|
||||
}
|
||||
|
||||
@@ -972,7 +969,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testCreateSingleBitstream_InputStreamNoAuth() throws Exception {
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it);
|
||||
itemService.createSingleBitstream(context, new FileInputStream(f), it);
|
||||
fail("Expected exception");
|
||||
}
|
||||
|
||||
@@ -1624,7 +1621,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
assertThat("testGetParentObject 1", itemService.getParentObject(context, it), notNullValue());
|
||||
assertThat("testGetParentObject 2", (Collection) itemService.getParentObject(context, it), equalTo(parent));
|
||||
} catch (AuthorizeException ex) {
|
||||
fail("Authorize exception catched");
|
||||
throw new AssertionError("Authorize Exception occurred", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,8 +9,6 @@ package org.dspace.content;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -21,12 +19,6 @@ import org.junit.Test;
|
||||
*/
|
||||
public class NonUniqueMetadataExceptionTest {
|
||||
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static final Logger log = LogManager
|
||||
.getLogger(NonUniqueMetadataExceptionTest.class);
|
||||
|
||||
/**
|
||||
* Dummy test to avoid initialization errors
|
||||
*/
|
||||
|
@@ -13,7 +13,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
@@ -137,7 +136,7 @@ public class RelationshipServiceImplTest {
|
||||
@Test
|
||||
public void testFindByItemAndRelationshipType() throws Exception {
|
||||
// Declare objects utilized in unit test
|
||||
List<Relationship> relList = new LinkedList<>();
|
||||
List<Relationship> relList = new ArrayList<>();
|
||||
Item item = mock(Item.class);
|
||||
RelationshipType testRel = new RelationshipType();
|
||||
|
||||
@@ -152,7 +151,7 @@ public class RelationshipServiceImplTest {
|
||||
@Test
|
||||
public void testFindByRelationshipType() throws Exception {
|
||||
// Declare objects utilized in unit test
|
||||
List<Relationship> relList = new LinkedList<>();
|
||||
List<Relationship> relList = new ArrayList<>();
|
||||
RelationshipType testRel = new RelationshipType();
|
||||
|
||||
// The Relationship(s) reported should match our our relList
|
||||
@@ -232,7 +231,6 @@ public class RelationshipServiceImplTest {
|
||||
|
||||
// Declare objects utilized in unit test
|
||||
MetadataValue metVal = mock(MetadataValue.class);
|
||||
List<MetadataValue> metsList = new ArrayList<>();
|
||||
List<Relationship> leftTypelist = new ArrayList<>();
|
||||
List<Relationship> rightTypelist = new ArrayList<>();
|
||||
Item leftItem = mock(Item.class);
|
||||
@@ -246,7 +244,6 @@ public class RelationshipServiceImplTest {
|
||||
testRel.setRightwardType("Entitylabel");
|
||||
testRel.setLeftMinCardinality(0);
|
||||
testRel.setRightMinCardinality(0);
|
||||
metsList.add(metVal);
|
||||
relationship = getRelationship(leftItem, rightItem, testRel, 0,0);
|
||||
leftTypelist.add(relationship);
|
||||
rightTypelist.add(relationship);
|
||||
|
@@ -48,11 +48,6 @@ public class ThumbnailTest extends AbstractUnitTest {
|
||||
*/
|
||||
private Bitstream orig;
|
||||
|
||||
/**
|
||||
* Thumbnail instance for the tests, original copy
|
||||
*/
|
||||
private Thumbnail t;
|
||||
|
||||
/**
|
||||
* This method will be run before every test as per @Before. It will
|
||||
* initialize resources required for the tests.
|
||||
@@ -69,7 +64,7 @@ public class ThumbnailTest extends AbstractUnitTest {
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
thumb = bitstreamService.create(context, new FileInputStream(f));
|
||||
orig = bitstreamService.create(context, new FileInputStream(f));
|
||||
t = new Thumbnail(thumb, orig);
|
||||
Thumbnail t = new Thumbnail(thumb, orig);
|
||||
} catch (IOException ex) {
|
||||
log.error("IO Error in init", ex);
|
||||
fail("SQL Error in init: " + ex.getMessage());
|
||||
@@ -91,7 +86,6 @@ public class ThumbnailTest extends AbstractUnitTest {
|
||||
public void destroy() {
|
||||
thumb = null;
|
||||
orig = null;
|
||||
t = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.AbstractIntegrationTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -1194,9 +1195,9 @@ public class ITDSpaceAIP extends AbstractIntegrationTest {
|
||||
|
||||
// Get the typeText & name of this object from the values
|
||||
String info = infoMap.get(key);
|
||||
String[] values = info.split(valueseparator);
|
||||
String typeText = values[0];
|
||||
String name = values[1];
|
||||
List<String> values = Splitter.on(valueseparator).splitToList(info);
|
||||
String typeText = values.get(0);
|
||||
String name = values.get(1);
|
||||
|
||||
// Also assert type and name are correct
|
||||
assertEquals("assertObjectsExist object " + key + " type",
|
||||
|
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.service.ItemService;
|
||||
@@ -107,17 +108,14 @@ public class ConcatenateTest {
|
||||
metadataValueList.add(metadataValue);
|
||||
String s = "dc.title";
|
||||
list.add(s);
|
||||
String[] splittedString = s.split("\\.");
|
||||
List<String> splittedString = Splitter.on(".").splitToList(s);
|
||||
concatenate.setFields(list);
|
||||
valueList.add("TestValue");
|
||||
|
||||
// Mock the state of objects utilized in getValues() to meet the success criteria of an invocation
|
||||
when(itemService.getMetadata(item, splittedString.length > 0 ? splittedString[0] :
|
||||
null,
|
||||
splittedString.length > 1 ? splittedString[1] :
|
||||
null,
|
||||
splittedString.length > 2 ? splittedString[2] :
|
||||
null,
|
||||
when(itemService.getMetadata(item, splittedString.size() > 0 ? splittedString.get(0) : null,
|
||||
splittedString.size() > 1 ? splittedString.get(1) : null,
|
||||
splittedString.size() > 2 ? splittedString.get(2) : null,
|
||||
Item.ANY, false)).thenReturn(metadataValueList);
|
||||
when(metadataValue.getValue()).thenReturn("TestValue");
|
||||
|
||||
|
@@ -13,7 +13,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -150,8 +149,8 @@ public class RelatedTest {
|
||||
assertEquals("TestGetValues 1", virtualMetadataConfiguration.getValues(context, item),
|
||||
related.getValues(context, item));
|
||||
related.setPlace(2);
|
||||
// No match should return empty LinkedList
|
||||
assertEquals("TestGetValues 2", new LinkedList<>(), related.getValues(context, item));
|
||||
// No match should return empty List
|
||||
assertEquals("TestGetValues 2", new ArrayList<>(), related.getValues(context, item));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
public class UUIDValueTest {
|
||||
|
||||
@InjectMocks
|
||||
private UUIDValue UUIDValue;
|
||||
private UUIDValue uuidValue;
|
||||
|
||||
@Mock
|
||||
private Context context;
|
||||
@@ -36,32 +36,32 @@ public class UUIDValueTest {
|
||||
@Test
|
||||
public void testGetValues() throws Exception {
|
||||
// Setup objects utilized in unit test
|
||||
List<String> list = new LinkedList<>();
|
||||
List<String> list = new ArrayList<>();
|
||||
Item item = mock(Item.class);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(item.getID()).thenReturn(uuid);
|
||||
list.add(String.valueOf(uuid));
|
||||
|
||||
// The reported value(s) should match our defined list
|
||||
assertEquals("TestGetValues 0", list, UUIDValue.getValues(context, item));
|
||||
assertEquals("TestGetValues 0", list, uuidValue.getValues(context, item));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetUseForPlace() {
|
||||
// Setup objects utilized in unit test
|
||||
UUIDValue.setUseForPlace(true);
|
||||
uuidValue.setUseForPlace(true);
|
||||
|
||||
// The reported boolean should return true
|
||||
assertEquals("TestSetUseForPlace 0", true, UUIDValue.getUseForPlace());
|
||||
assertEquals("TestSetUseForPlace 0", true, uuidValue.getUseForPlace());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUseForPlace() {
|
||||
// Setup objects utilized in unit test
|
||||
UUIDValue.setUseForPlace(true);
|
||||
uuidValue.setUseForPlace(true);
|
||||
|
||||
// The reported boolean should return true
|
||||
assertEquals("TestGetUseForPlace 0", true, UUIDValue.getUseForPlace());
|
||||
assertEquals("TestGetUseForPlace 0", true, uuidValue.getUseForPlace());
|
||||
}
|
||||
}
|
||||
|
@@ -8,8 +8,8 @@
|
||||
package org.dspace.external.provider.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -28,10 +28,12 @@ public class MockDataProvider implements ExternalDataProvider {
|
||||
* Generic getter for the sourceIdentifier
|
||||
* @return the sourceIdentifier value of this MockDataProvider
|
||||
*/
|
||||
@Override
|
||||
public String getSourceIdentifier() {
|
||||
return sourceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
||||
ExternalDataObject externalDataObject = mockLookupMap.get(id);
|
||||
if (externalDataObject == null) {
|
||||
@@ -41,8 +43,9 @@ public class MockDataProvider implements ExternalDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
||||
List<ExternalDataObject> listToReturn = new LinkedList<>();
|
||||
List<ExternalDataObject> listToReturn = new ArrayList<>();
|
||||
for (Map.Entry<String, ExternalDataObject> entry : mockLookupMap.entrySet()) {
|
||||
if (StringUtils.containsIgnoreCase(entry.getKey(), query)) {
|
||||
listToReturn.add(entry.getValue());
|
||||
@@ -72,7 +75,7 @@ public class MockDataProvider implements ExternalDataProvider {
|
||||
|
||||
public void init() throws IOException {
|
||||
mockLookupMap = new HashMap<>();
|
||||
List<String> externalDataObjectsToMake = new LinkedList<>();
|
||||
List<String> externalDataObjectsToMake = new ArrayList<>();
|
||||
externalDataObjectsToMake.add("one");
|
||||
externalDataObjectsToMake.add("two");
|
||||
externalDataObjectsToMake.add("three");
|
||||
@@ -83,7 +86,7 @@ public class MockDataProvider implements ExternalDataProvider {
|
||||
externalDataObject.setId(id);
|
||||
externalDataObject.setValue(id);
|
||||
externalDataObject.setDisplayValue(id);
|
||||
List<MetadataValueDTO> list = new LinkedList<>();
|
||||
List<MetadataValueDTO> list = new ArrayList<>();
|
||||
list.add(new MetadataValueDTO("dc", "contributor", "author", null, "Donald, Smith"));
|
||||
externalDataObject.setMetadata(list);
|
||||
|
||||
|
@@ -128,12 +128,8 @@ public class HandleDAOImplTest extends AbstractUnitTest {
|
||||
owningCommunity = context.reloadEntity(owningCommunity);
|
||||
ContentServiceFactory.getInstance().getCommunityService().delete(context, owningCommunity);
|
||||
owningCommunity = null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AuthorizeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Error occurred in destroy()", e);
|
||||
}
|
||||
item1 = null;
|
||||
item2 = null;
|
||||
|
@@ -11,11 +11,11 @@ package org.dspace.statistics.util;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -114,7 +114,7 @@ public class DummyHttpServletRequest implements HttpServletRequest {
|
||||
* @param headerValue The value of the header
|
||||
*/
|
||||
public void addHeader(String headerName, String headerValue) {
|
||||
List<String> values = headers.computeIfAbsent(headerName, k -> new LinkedList<>());
|
||||
List<String> values = headers.computeIfAbsent(headerName, k -> new ArrayList<>());
|
||||
values.add(headerValue);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
@@ -271,7 +271,7 @@ public class BasicWorkflowAuthorizationIT
|
||||
Item item = wsi.getItem();
|
||||
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
||||
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||
bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||
bundleService.update(context, bundle);
|
||||
itemService.update(context, item);
|
||||
workspaceItemService.update(context, wsi);
|
||||
@@ -323,7 +323,7 @@ public class BasicWorkflowAuthorizationIT
|
||||
Item item = wsi.getItem();
|
||||
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
||||
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||
bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||
bundleService.update(context, bundle);
|
||||
itemService.update(context, item);
|
||||
workspaceItemService.update(context, wsi);
|
||||
@@ -365,7 +365,7 @@ public class BasicWorkflowAuthorizationIT
|
||||
item.setSubmitter(submitter);
|
||||
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
||||
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||
bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||
bundleService.update(context, bundle);
|
||||
itemService.update(context, item);
|
||||
workspaceItemService.update(context, wsi);
|
||||
|
Reference in New Issue
Block a user