/** * {@inheritDoc} */ @Override public IStorageDescriptor get(E element) { for (IStorageTreeComponent<E> branch : branches) { IStorageDescriptor descriptor = branch.get(element); if (descriptor != null) { return descriptor; } } return null; }
/** * Test that get will work even when branch can not generate key for the element if ID is * correctly set. * * @throws IndexingException */ @Test public void getWithNoKey() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false)); InvocationSequenceData invocation = mock(InvocationSequenceData.class); when(invocation.getId()).thenReturn(1L); when(invocation.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); IStorageDescriptor storageDescriptor = rootBranch.put(invocation); when(invocation.getTimeStamp()).thenReturn(null); // test get assertThat(rootBranch.get(invocation), is(equalTo(storageDescriptor))); // then get and remove assertThat(rootBranch.getAndRemove(invocation), is(equalTo(storageDescriptor))); // confirm it is removed assertThat(rootBranch.get(invocation), is(nullValue())); }
/** * Test that the get on the {@link LeafWithNoDescriptors} will throw an exception if invoked. * * @throws IndexingException * If {@link IndexingException} occurs. */ @Test(expectedExceptions = { UnsupportedOperationException.class }) public void putAndGetElement() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new LeafWithNoDescriptors<>(); DefaultData defaultData = mock(DefaultData.class); when(defaultData.getId()).thenReturn(1L); rootBranch.put(defaultData); rootBranch.get(defaultData); }
/** * Test that putting one element will return the same {@link IStorageDescriptor} as when get is * executed.. * * @throws IndexingException * If {@link IndexingException} occurs. */ @Test public void putAndGetInvocation() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), false)); InvocationSequenceData invocationSequenceData = new InvocationSequenceData(); invocationSequenceData.setId(1L); IStorageDescriptor storageDescriptor = rootBranch.put(invocationSequenceData); assertThat(storageDescriptor, comparesEqualTo(rootBranch.get(invocationSequenceData))); }