Skip to content

Commit

Permalink
turn off some expected logging messages in tests (#2782)
Browse files Browse the repository at this point in the history
* turn off some expected logging messages
* silence more warnings
* default level to null
  • Loading branch information
elharo authored Feb 8, 2018
1 parent 2425972 commit f070b08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.cloud.tools.eclipse.appengine.libraries.model.LibraryFile;
import com.google.cloud.tools.eclipse.appengine.libraries.model.MavenCoordinates;
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator;
import com.google.cloud.tools.eclipse.util.ArtifactRetriever;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -29,13 +31,17 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -70,6 +76,15 @@ public void setUp() throws SAXException, IOException, CoreException {
pomFile.create(in, IFile.FORCE, null);

pom = Pom.parse(pomFile);

Logger logger = Logger.getLogger(ArtifactRetriever.class.getName());
logger.setLevel(Level.OFF);
}

@After
public void tearDown() throws SAXException, IOException, CoreException {
Logger logger = Logger.getLogger(ArtifactRetriever.class.getName());
logger.setLevel(null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.Test;

import com.google.cloud.tools.eclipse.util.ArtifactRetriever;

public class LibraryTest {

private Library library = new Library("a");

@Test(expected = NullPointerException.class)
public void testConstructorNullArgument() {
new Library(null);
Expand All @@ -62,7 +67,6 @@ public void testSetRelease() {
assertThat(library.getLaunchStage(), is("beta"));
}


@Test
public void testSetNullName() {
library.setName(null);
Expand Down Expand Up @@ -116,17 +120,28 @@ public void setLibraryFilesNullDoesNotChangeIt() {
}

@Test
public void setLibraryFiles() {
MavenCoordinates mavenCoordinates =
new MavenCoordinates.Builder().setGroupId("groupId").setArtifactId("artifactId").build();
library.setLibraryFiles(Arrays.asList(new LibraryFile(mavenCoordinates)));
List<LibraryFile> allDependencies = library.getAllDependencies();
assertNotNull(allDependencies);
assertThat(allDependencies.size(), is(1));
LibraryFile actual = allDependencies.get(0);
assertThat(actual.getMavenCoordinates().getRepository(), is("central"));
assertThat(actual.getMavenCoordinates().getGroupId(), is("groupId"));
assertThat(actual.getMavenCoordinates().getArtifactId(), is("artifactId"));
public void testSetLibraryFiles() {
Logger logger = Logger.getLogger(ArtifactRetriever.class.getName());
Logger logger2 = Logger.getLogger(Library.class.getName());

try {
logger.setLevel(Level.OFF);
logger2.setLevel(Level.OFF);

MavenCoordinates mavenCoordinates =
new MavenCoordinates.Builder().setGroupId("groupId").setArtifactId("artifactId").build();
library.setLibraryFiles(Arrays.asList(new LibraryFile(mavenCoordinates)));
List<LibraryFile> allDependencies = library.getAllDependencies();
assertNotNull(allDependencies);
assertThat(allDependencies.size(), is(1));
LibraryFile actual = allDependencies.get(0);
assertThat(actual.getMavenCoordinates().getRepository(), is("central"));
assertThat(actual.getMavenCoordinates().getGroupId(), is("groupId"));
assertThat(actual.getMavenCoordinates().getArtifactId(), is("artifactId"));
} finally {
logger.setLevel(null);
logger2.setLevel(null);
}
}

@Test
Expand Down

0 comments on commit f070b08

Please sign in to comment.