Permalink
Browse files

Create JUnit Rule for verifying log entries

- Create a LogVerifier (to be used with JUnit's @Rule) that provides a
  MavenLogger instance and performs assertions on the errors/warnings
  written to that logger.
- Used the verifier in most tests. Dropped (one of the) other logger
  stub implementations.

Change-Id: I8a89a10e123a279fa187070172281b78046fd127
  • Loading branch information...
1 parent eaa3a9a commit 4275a8fbe07b82ba61f6b8fd51ba3bc7b4e07f91 @oberlies oberlies committed Feb 15, 2013
Showing with 299 additions and 167 deletions.
  1. +5 −3 ...en.repository.tests/src/test/java/org/eclipse/tycho/repository/local/BaseMavenRepositoryTest.java
  2. +6 −6 ...l.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverAdditionalRequirementsTest.java
  3. +6 −4 ....tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverTest.java
  4. +2 −2 ...ho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverTestBase.java
  5. +0 −80 ...pse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/test/MavenLoggerStub.java
  6. +5 −3 ...resolver.impl.test/src/test/java/org/eclipse/tycho/p2/remote/RemoteAgentDisableP2MirrorsTest.java
  7. +6 −6 ....p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/remote/RemoteAgentMavenMirrorsTest.java
  8. +6 −5 ...p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/remote/RemoteAgentMetadataCacheTest.java
  9. +6 −2 ...ho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/resolver/DependencyCollectorTest.java
  10. +6 −2 ...solver.impl.test/src/test/java/org/eclipse/tycho/p2/resolver/ProjectorResolutionStrategyTest.java
  11. +5 −4 ...t/src/test/java/org/eclipse/tycho/p2/target/TargetDefinitionResolverExecutionEnvironmentTest.java
  12. +10 −6 ...impl.test/src/test/java/org/eclipse/tycho/p2/target/TargetDefinitionResolverIncludeModeTests.java
  13. +8 −9 ...p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/target/TargetDefinitionResolverTest.java
  14. +6 −4 .../test/java/org/eclipse/tycho/p2/target/TargetDefinitionResolverWithPlatformSpecificUnitsTest.java
  15. +8 −3 ...solver.impl.test/src/test/java/org/eclipse/tycho/p2/target/TargetPlatformBundlePublisherTest.java
  16. +9 −11 ...mpl.test/src/test/java/org/eclipse/tycho/p2/target/filters/TargetPlatformFilterEvaluatorTest.java
  17. +11 −10 ....tools.tests/src/main/java/org/eclipse/tycho/p2/tools/mirroring/MirrorApplicationServiceTest.java
  18. +5 −5 ...tycho.p2.tools.tests/src/main/java/org/eclipse/tycho/p2/tools/mirroring/MirrorStandaloneTest.java
  19. +186 −0 ...o-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/LogVerifier.java
  20. +3 −2 tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/MemoryLog.java
@@ -20,7 +20,7 @@
import org.eclipse.tycho.p2.impl.repo.LocalRepositoryP2IndicesImpl;
import org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices;
import org.eclipse.tycho.p2.repository.TychoRepositoryIndex;
-import org.eclipse.tycho.test.util.MemoryLog;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.eclipse.tycho.test.util.NoopFileLockService;
import org.junit.Before;
import org.junit.Rule;
@@ -29,15 +29,17 @@
public abstract class BaseMavenRepositoryTest {
@Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
+ public final TemporaryFolder tempFolder = new TemporaryFolder();
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
protected LocalRepositoryP2Indices localRepoIndices;
protected File baseDir;
@Before
public void createLocalRepoIndices() {
baseDir = tempFolder.newFolder("repository");
- MavenContext mavenContext = new MavenContextImpl(baseDir, false, new MemoryLog(), new Properties());
+ MavenContext mavenContext = new MavenContextImpl(baseDir, false, logVerifier.getLogger(), new Properties());
LocalRepositoryP2IndicesImpl tempLocalRepoIndices = new LocalRepositoryP2IndicesImpl();
tempLocalRepoIndices.setMavenContext(mavenContext);
tempLocalRepoIndices.setFileLockService(new NoopFileLockService());
@@ -19,29 +19,29 @@
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.Version;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
import org.eclipse.tycho.p2.resolver.facade.P2Resolver;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
public class P2ResolverAdditionalRequirementsTest {
private static final String BUNDLE_NAMESPACE = "osgi.bundle";
-
private static final String IU_NAMESPACE = IInstallableUnit.NAMESPACE_IU_ID;
-
private static final String BUNDLE_TYPE = "eclipse-plugin";
-
private static final String IU_TYPE = P2Resolver.TYPE_INSTALLABLE_UNIT;
-
private static final String TARGET_UNIT_ID = "testbundleName";
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
+
private P2ResolverImpl impl;
@Before
public void initBlankResolver() {
- impl = new P2ResolverImpl(new MavenLoggerStub());
+ impl = new P2ResolverImpl(logVerifier.getLogger());
}
@Test
@@ -29,26 +29,28 @@
import java.util.Set;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.tycho.core.facade.MavenLogger;
import org.eclipse.tycho.core.facade.TargetEnvironment;
import org.eclipse.tycho.p2.impl.publisher.DependencyMetadata;
import org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator;
import org.eclipse.tycho.p2.impl.test.ArtifactMock;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
import org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult;
import org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult.Entry;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
public class P2ResolverTest extends P2ResolverTestBase {
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
+
@Before
public void initDefaultResolver() throws Exception {
org.eclipse.equinox.internal.p2.core.helpers.Tracing.DEBUG_PLANNER_PROJECTOR = true;
- MavenLogger logger = new MavenLoggerStub();
context = createTargetPlatformBuilder();
- impl = new P2ResolverImpl(logger);
+ impl = new P2ResolverImpl(logVerifier.getLogger());
impl.setEnvironments(getEnvironments());
}
@@ -30,7 +30,6 @@
import org.eclipse.tycho.p2.impl.publisher.P2GeneratorImpl;
import org.eclipse.tycho.p2.impl.repo.LocalRepositoryP2IndicesImpl;
import org.eclipse.tycho.p2.impl.test.ArtifactMock;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
import org.eclipse.tycho.p2.metadata.IDependencyMetadata;
import org.eclipse.tycho.p2.remote.RemoteAgent;
import org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices;
@@ -46,6 +45,7 @@
import org.eclipse.tycho.repository.local.LocalArtifactRepository;
import org.eclipse.tycho.repository.local.LocalMetadataRepository;
import org.eclipse.tycho.test.util.BuildPropertiesParserForTesting;
+import org.eclipse.tycho.test.util.MemoryLog;
import org.eclipse.tycho.test.util.NoopFileLockService;
import org.junit.Before;
@@ -128,7 +128,7 @@ protected final TargetPlatformBuilderImpl createTargetPlatformBuilderWithCustomE
TestTargetPlatformBuilderFactory() throws Exception {
boolean offline = false;
- mavenContext = createMavenContext(offline, new MavenLoggerStub());
+ mavenContext = createMavenContext(offline, new MemoryLog());
targetDefinitionResolverService = new TargetDefinitionResolverService(mavenContext);
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Sonatype Inc. and others.
- * 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
- *
- * Contributors:
- * Sonatype Inc. - initial API and implementation
- * SAP AG - added verification functionality
- *******************************************************************************/
-package org.eclipse.tycho.p2.impl.test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tycho.core.facade.MavenLogger;
-
-public class MavenLoggerStub implements MavenLogger {
-
- private final boolean failOnWarning;
- private final boolean failOnError;
- private final List<String> errors = new ArrayList<String>();
- private final List<String> warnings = new ArrayList<String>();
- private final List<String> debugs = new ArrayList<String>();
-
- public MavenLoggerStub() {
- this(false, true);
- }
-
- public MavenLoggerStub(boolean failOnWarning, boolean failOnError) {
- this.failOnWarning = failOnWarning;
- this.failOnError = failOnError;
- }
-
- public void error(String message) {
- if (failOnError) {
- throw new RuntimeException("Error logged: " + message);
- }
- errors.add(message);
- }
-
- public void warn(String message) {
- warn(message, null);
- }
-
- public void warn(String message, Throwable cause) {
- if (failOnWarning)
- throw new RuntimeException("Unexpected warning logged: " + message, cause);
- warnings.add(message);
- }
-
- public List<String> getErrors() {
- return errors;
- }
-
- public List<String> getWarnings() {
- return warnings;
- }
-
- public final List<String> getDebugs() {
- return debugs;
- }
-
- public void info(String message) {
- }
-
- public void debug(String message) {
- debugs.add(message);
- }
-
- public boolean isExtendedDebugEnabled() {
- // run through message preparation code in tests
- return true;
- }
-
- public boolean isDebugEnabled() {
- return true;
- }
-}
@@ -24,8 +24,8 @@
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.tycho.core.facade.MavenContextImpl;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
import org.eclipse.tycho.p2.impl.test.ResourceUtil;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -34,7 +34,9 @@
public class RemoteAgentDisableP2MirrorsTest {
@Rule
- public TemporaryFolder tempManager = new TemporaryFolder();
+ public final TemporaryFolder tempManager = new TemporaryFolder();
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
@Before
public void setUp() throws Exception {
@@ -58,7 +60,7 @@ public void testWithoutDisableP2Mirrors() throws Exception {
private IProvisioningAgent createRemoteAgent(boolean disableMirrors) throws ProvisionException {
File localRepo = tempManager.newFolder("localRepo");
- return new RemoteAgent(new MavenContextImpl(localRepo, false, new MavenLoggerStub(), new Properties()),
+ return new RemoteAgent(new MavenContextImpl(localRepo, false, logVerifier.getLogger(), new Properties()),
disableMirrors);
}
@@ -28,12 +28,11 @@
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.tycho.core.facade.MavenContext;
import org.eclipse.tycho.core.facade.MavenContextImpl;
-import org.eclipse.tycho.core.facade.MavenLogger;
import org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation;
import org.eclipse.tycho.core.resolver.shared.MavenRepositorySettings;
import org.eclipse.tycho.p2.impl.test.ResourceUtil;
import org.eclipse.tycho.test.util.HttpServer;
-import org.eclipse.tycho.test.util.MemoryLog;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -44,9 +43,9 @@
private static final boolean OFFLINE = false;
@Rule
- public TemporaryFolder tempManager = new TemporaryFolder();
-
- private MavenLogger logger = new MemoryLog();
+ public final TemporaryFolder tempManager = new TemporaryFolder();
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
private HttpServer localServer;
@@ -61,7 +60,8 @@ public void initServer() throws Exception {
@Before
public void initSubject() throws ProvisionException {
File localRepository = tempManager.newFolder("localRepo");
- MavenContext mavenContext = new MavenContextImpl(localRepository, OFFLINE, logger, new Properties());
+ MavenContext mavenContext = new MavenContextImpl(localRepository, OFFLINE, logVerifier.getLogger(),
+ new Properties());
mavenRepositorySettings = new MavenRepositorySettingsStub();
subject = new RemoteAgent(mavenContext, mavenRepositorySettings, OFFLINE);
@@ -23,9 +23,8 @@
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.tycho.core.facade.MavenContextImpl;
-import org.eclipse.tycho.core.facade.MavenLogger;
import org.eclipse.tycho.test.util.HttpServer;
-import org.eclipse.tycho.test.util.MemoryLog;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -44,7 +43,7 @@
private File localMavenRepository;
- private MavenLogger logger = new MemoryLog();
+ private LogVerifier logVerifier = new LogVerifier();
@Before
public void startHttpServer() throws Exception {
@@ -125,11 +124,13 @@ public void testOnlineReloadingDoesntReloadFromRemote() throws Exception {
}
private RemoteAgent newOnlineAgent() throws Exception {
- return new RemoteAgent(new MavenContextImpl(localMavenRepository, false, logger, new Properties()));
+ return new RemoteAgent(new MavenContextImpl(localMavenRepository, false, logVerifier.getLogger(),
+ new Properties()));
}
private RemoteAgent newOfflineAgent() throws Exception {
- return new RemoteAgent(new MavenContextImpl(localMavenRepository, true, logger, new Properties()));
+ return new RemoteAgent(new MavenContextImpl(localMavenRepository, true, logVerifier.getLogger(),
+ new Properties()));
}
private IMetadataRepository loadHttpRepository(RemoteAgent agent) throws ProvisionException {
@@ -23,15 +23,19 @@
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Assert;
+import org.junit.Rule;
import org.junit.Test;
public class DependencyCollectorTest {
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
+
@Test
public void missingDependencies() {
- DependencyCollector dc = new DependencyCollector(new MavenLoggerStub());
+ DependencyCollector dc = new DependencyCollector(logVerifier.getLogger());
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
String time = Long.toString(System.currentTimeMillis());
@@ -33,9 +33,10 @@
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
import org.eclipse.tycho.test.util.InstallableUnitUtil;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
@SuppressWarnings("restriction")
@@ -54,11 +55,14 @@ private CollectionQueryable(Collection<IInstallableUnit> ius) {
}
}
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
+
private ProjectorResolutionStrategy strategy;
@Before
public void setup() {
- strategy = new ProjectorResolutionStrategy(new MavenLoggerStub());
+ strategy = new ProjectorResolutionStrategy(logVerifier.getLogger());
strategy.setRootInstallableUnits(Collections.<IInstallableUnit> emptyList());
}
@@ -25,29 +25,30 @@
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.VersionedId;
-import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
import org.eclipse.tycho.p2.target.TargetDefinitionResolverIncludeModeTests.PlannerLocationStub;
import org.eclipse.tycho.p2.target.TargetDefinitionResolverTest.LocationStub;
import org.eclipse.tycho.p2.target.TargetDefinitionResolverTest.RepositoryStub;
import org.eclipse.tycho.p2.target.ee.StandardEEResolutionHints;
import org.eclipse.tycho.p2.target.facade.TargetDefinition;
import org.eclipse.tycho.p2.target.facade.TargetDefinition.IncludeMode;
import org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository;
+import org.eclipse.tycho.test.util.LogVerifier;
import org.eclipse.tycho.test.util.P2Context;
import org.junit.Rule;
import org.junit.Test;
public class TargetDefinitionResolverExecutionEnvironmentTest {
@Rule
- public P2Context p2Context = new P2Context();
+ public final P2Context p2Context = new P2Context();
+ @Rule
+ public final LogVerifier logVerifier = new LogVerifier();
- private MavenLoggerStub logger = new MavenLoggerStub();
private TargetDefinitionResolver subject;
private TargetDefinitionResolver targetResolverForEE(String executionEnvironment) throws ProvisionException {
return new TargetDefinitionResolver(defaultEnvironments(), new StandardEEResolutionHints(executionEnvironment),
- p2Context.getAgent(), logger);
+ p2Context.getAgent(), logVerifier.getLogger());
}
@Test
Oops, something went wrong.

0 comments on commit 4275a8f

Please sign in to comment.