Skip to content

Commit

Permalink
Merge pull request #2 from defer/master
Browse files Browse the repository at this point in the history
Add the guava-testlib harness
  • Loading branch information
giltene committed Jun 15, 2014
2 parents b2a3b04 + a721fe2 commit e837692
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -185,5 +185,11 @@
<version>4.10</version>
<scope>test/java/org/giltene</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>17.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
90 changes: 90 additions & 0 deletions src/test/java/org/giltene/PauselessHashMapGuavaTest.java
@@ -0,0 +1,90 @@
/*
* Copyright 2014 Diogo Ferreira
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.giltene;

import com.google.common.collect.testing.MapTestSuiteBuilder;
import com.google.common.collect.testing.TestStringMapGenerator;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import junit.framework.Test;
import junit.framework.TestSuite;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
* Tests the map using the guava test harness.
*
* @author Diogo Ferreira (diogo.ferreira@feedzai.com)
*/
public class PauselessHashMapGuavaTest {
public static Test suite() {
return new PauselessHashMapGuavaTest().allTests();
}

public Test allTests() {
TestSuite suite = new TestSuite("org.giltene PauselessHashMap");
suite.addTest(testsForPauselessHashMap());
return suite;
}

public Test testsForPauselessHashMap() {
return MapTestSuiteBuilder
.using(new TestStringMapGenerator() {
@Override
protected Map<String, String> create(
Map.Entry<String, String>[] entries) {
return toHashMap(entries);
}
})
.named("HashMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
MapFeature.ALLOWS_ANY_NULL_QUERIES,
MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForHashMap())
.createTestSuite();
}

private static Map<String, String> toHashMap(
Map.Entry<String, String>[] entries) {
return populate(new PauselessHashMap<String, String>(), entries);
}

private static <T, M extends Map<T, String>> M populate(
M map, Map.Entry<T, String>[] entries) {
for (Map.Entry<T, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}

protected Collection<Method> suppressForHashMap() {
return Collections.emptySet();
}
}

0 comments on commit e837692

Please sign in to comment.