blob: 35d15578ee619f99b134b69ab445845877832851 [file] [log] [blame]
/**
* Copyright (c) 2016 Codetrails GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.epp.logging.aeri.ide.processors;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.epp.internal.logging.aeri.ide.IProcessorDescriptor;
import org.eclipse.epp.internal.logging.aeri.ide.utils.IDEConstants;
import org.eclipse.epp.logging.aeri.core.IModelFactory;
import org.eclipse.epp.logging.aeri.core.IReport;
import org.junit.Before;
import org.junit.Test;
public class CachingStringProcessorTest {
public class TestCachingStringProcessor extends AbstractCachingStringProcessor {
private TestCachingStringProcessor(IProcessorDescriptor descriptor) {
super(descriptor);
}
@Override
public boolean wantsToContribute(IStatus status, IEclipseContext context) {
return true;
}
@Override
protected String process(IStatus status) {
return "";
}
@Override
protected boolean canContribute(IStatus status) {
return true;
}
}
private AbstractCachingStringProcessor sut;
private IModelFactory MF = IModelFactory.eINSTANCE;
private IEclipseContext context;
private IStatus status;
@Before
public void setUp() {
IProcessorDescriptor descriptor = mock(IProcessorDescriptor.class);
when(descriptor.getDirective()).thenReturn("test information");
sut = spy(new TestCachingStringProcessor(descriptor));
context = EclipseContextFactory.create();
status = new Status(Status.ERROR, IDEConstants.BUNDLE_ID, "test error status");
}
@Test
public void testProcess() {
IReport report = MF.createReport();
assertThat(report.getAuxiliaryInformation(), is(empty()));
sut.process(report, status, context);
assertThat(report.getAuxiliaryInformation(), not(empty()));
}
@Test
public void testAnalyzeOnce() {
IReport report = MF.createReport();
sut.process(report, status, context);
sut.process(report, status, context);
sut.process(report, status, context);
verify(sut, times(1)).process(status);
}
}