List of usage examples for org.apache.commons.collections CollectionUtils get
public static Object get(Object object, int index)
index
-th value in object
, throwing IndexOutOfBoundsException
if there is no such element or IllegalArgumentException
if object
is not an instance of one of the supported types. From source file:hr.fer.zemris.vhdllab.service.workspace.ProjectMetadataTest.java
@Test public void getFiles2() { File file = (File) CollectionUtils.get(metadata.getFiles(), 0); file.setName("new_name"); File another = (File) CollectionUtils.get(metadata.getFiles(), 0); assertTrue(file.equals(another));//from w w w . j a v a 2 s.c om }
From source file:hr.fer.zemris.vhdllab.service.workspace.WorkspaceTest.java
@Test public void constructor() { workspace = new Workspace(projectMetadata, predefinedFiles, preferencesFiles); assertEquals(3, workspace.getProjectCount()); for (Project project : workspace.getProjects()) { assertNull(project.getFiles());// ww w .j a v a2 s.c om } assertEquals(predefinedFiles.size(), workspace.getPredefinedFiles().size()); File file = (File) CollectionUtils.get(workspace.getPredefinedFiles(), 0); assertNull(file.getProject()); file = (File) CollectionUtils.get(predefinedFiles, 0); file.setName("new_name"); file = (File) CollectionUtils.get(workspace.getPredefinedFiles(), 0); assertEquals("predefined", file.getName()); PreferencesFile preferencesFile = preferencesFiles.get(0); preferencesFile.setName("new_name"); preferencesFile = workspace.getPreferencesFiles().get(0); assertEquals("preferences1", preferencesFile.getName()); }
From source file:com.redhat.rhn.domain.server.test.ServerFactoryVirtualizationTest.java
public void testUpdateGuestAndSaveHost() throws Exception { // testUpdateGuest() tests updating an already persistent guest. In order to do // this, we need to: ///* w w w.j av a 2s . c om*/ // 1) Add a guest to the server. // 2) Save the host (and the guest). // 3) Modify the guest outside of a hibernate session. // 4) Repeat step one. // 5) Retrieve the server and test that it contains the modified guest. Server host = ServerFactoryTest.createTestServer(user); host.addGuest(virtualInstanceFactory.newRegisteredGuestWithoutHost()); ServerFactory.save(host); flushAndEvict(host); VirtualInstance virtualInstance = (VirtualInstance) CollectionUtils.get(host.getGuests(), 0); String uuid = "abcd"; virtualInstance.setUuid(uuid); ServerFactory.save(host); flushAndEvict(host); Server retrievedHost = ServerFactory.lookupById(host.getId()); assertTrue(retrievedHost.getGuests().contains(virtualInstance)); }
From source file:hr.fer.zemris.vhdllab.entity.ProjectTest.java
/** * Add a file that is already in that project. *//* w ww .ja v a 2 s . c o m*/ @Test public void addFile2() throws Exception { Set<File> files = new HashSet<File>(entity.getFiles()); File file = (File) CollectionUtils.get(entity.getFiles(), 0); entity.addFile(file); assertEquals("files not same.", files, entity.getFiles()); assertEquals("files is changed.", 1, entity.getFiles().size()); }
From source file:hr.fer.zemris.vhdllab.entity.ProjectTest.java
/** * Add a file that is already in another project. *//* w w w. j a va 2 s .c o m*/ @Test(expected = IllegalArgumentException.class) public void addFile3() throws Exception { Project another = new Project(entity); File file = (File) CollectionUtils.get(entity.getFiles(), 0); another.addFile(file); }
From source file:curam.molsa.test.customfunctions.MOLSADOMReader.java
/** * Get String from query./*from w w w. j a v a 2 s .com*/ * * @param startElement * @param query * @return CollectionUtils */ public static String string(final Object startElement, final String query) { final List<String> values = strings(startElement, query); if (values.isEmpty()) { return null; } return (String) CollectionUtils.get(values, 0); }
From source file:hr.fer.zemris.vhdllab.entity.ProjectTest.java
/** * Remove a file.//from ww w. ja v a 2s . com */ @Test public void removeFile() throws Exception { File file = (File) CollectionUtils.get(entity.getFiles(), 0); entity.removeFile(file); assertTrue("files not empty.", entity.getFiles().isEmpty()); assertNull("project isn't set to null.", file.getProject()); }
From source file:hr.fer.zemris.vhdllab.entity.ProjectTest.java
/** * Remove a file that belongs to another project. *//*from w w w. ja v a 2 s . c o m*/ @Test(expected = IllegalArgumentException.class) public void removeFile3() throws Exception { File file = (File) CollectionUtils.get(entity.getFiles(), 0); Project another = new Project(entity); another.removeFile(file); }
From source file:hr.fer.zemris.vhdllab.service.workspace.WorkspaceTest.java
@Test public void addProject2() { Project project = new Project("user", "name"); workspace.addProject(project);//from w w w . ja v a2 s .co m assertEquals(4, workspace.getProjectCount()); assertEquals(4, workspace.getProjects().size()); assertNotNull(workspace.getFiles(project)); assertNotNull(workspace.getHierarchy(project)); project.setId(34); workspace.addProject(project); assertEquals(4, workspace.getProjectCount()); assertEquals(4, workspace.getProjects().size()); assertNotNull(workspace.getFiles(project)); assertNotNull(workspace.getHierarchy(project)); assertEquals(Integer.valueOf(34), workspace.getHierarchy(project).getProject().getId()); int index = workspace.getProjects().indexOf(project); Project fromListProject = (Project) CollectionUtils.get(workspace.getProjects(), index); assertEquals(Integer.valueOf(34), fromListProject.getId()); }
From source file:hr.fer.zemris.vhdllab.service.workspace.ProjectMetadataTest.java
@Test public void removeFile2() { File file = (File) CollectionUtils.get(metadata.getFiles(), 0); metadata.removeFile(file);//from ww w.j av a 2s . co m assertEquals(1, metadata.getFiles().size()); assertFalse(metadata.getFiles().contains(file)); }