Skip to content

Instantly share code, notes, and snippets.

View compwron's full-sized avatar
💭
https://github.com/drop-ice/dear-github-2.0

compwron compwron

💭
https://github.com/drop-ice/dear-github-2.0
View GitHub Profile
@compwron
compwron / testutils.java
Created July 9, 2017 21:59
testutils from package dragnon;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.junit.Assert.fail;
@SuppressWarnings("unchecked")
private Matcher<ErrorCollector> containsErrorCode(final ErrorCode errorCode) {
return new BaseMatcher<ErrorCollector>() {
@Override
public boolean matches(final Object item) {
ErrorCollector allErrors = (ErrorCollector) item;
FieldError fieldError = allErrors.getFieldError(errorCode.getField());
if (fieldError == null) {
return false;
}
if (!fieldError.getCode().equals(errorCode.getCode())) {
@compwron
compwron / snippet.java
Created May 11, 2017 13:11
hamcrest matcher for http status
private Matcher<ResponseEntity<String>> httpStatus(final HttpStatus httpStatus) {
return new BaseMatcher<ResponseEntity<String>>() {
@Override
public boolean matches(final Object item) {
final ResponseEntity<String> responseEntity = (ResponseEntity<String>) item;
return httpStatus.equals(responseEntity.getStatusCode());
}
@Override
public void describeTo(final Description description) {
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions: [SafeCommitHook]>
Integration: Mutant::Integration::Rspec
Jobs: 1
Includes: ["lib"]
Requires: []
(00/932) 100% - killtime: 0.00s runtime: 0.00s overhead: 0.00s
(00/932) 100% - killtime: 0.00s runtime: 0.00s overhead: 0.00s
(00/932) 100% - killtime: 0.00s runtime: 1.01s overhead: 1.01s
(04/932) 100% - killtime: 1.66s runtime: 2.01s overhead: 0.35s
@compwron
compwron / PhantoJS.java
Created December 29, 2016 18:14 — forked from rameshbaskar/PhantomJS.java
Replacing Firefox driver to PhantomJS driver
// Current Implementation - Using FirefoxDriver
@Before
public static void before() {
driver = new FirefoxDriver();
admin = new AdminApi();
user = new UserApi(driver);
screen = new ScreenApi(driver);
}
@compwron
compwron / TimestampsTest.java
Created December 8, 2016 15:08
TimestampsTest osa being awesome
import org.junit.Test;
import org.reflections.Reflections;
import javax.persistence.Entity;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@compwron
compwron / timestamptest.java
Created December 7, 2016 00:31
test that all spring db objects have timestamps
public class SanityDbComponentTest {
@Test
public void foo() throws Exception {
Reflections reflections = new Reflections("com.sonicdrivein");
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class);
@compwron
compwron / SanityTest
Last active September 12, 2017 15:48
try to test any spring crud codebase to make sure that timestamps are present on db tables
@Test
public void foo() throws Exception {
// find all classes that extend CrudRepository
// find the object that the repository is for
// check that object has .getCreatedAt and .getUpdatedAt with the Timestamp type
// https://stackoverflow.com/questions/492184/how-do-you-find-all-subclasses-of-a-given-class-in-java
// ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
// provider.addIncludeFilter(new AssignableTypeFilter(CrudRepository.class));
//
@compwron
compwron / dependency_resolver.rb
Created October 14, 2016 17:05
guesses dependencies from bundler error messages as of 12 Oct 2016
class DependencyResolver
COMMAND = "rm -rf Gemfile.lock ; bundle install ; ruby lib/foo.rb 2>&1"
LOCKED_GEM = /.*locked to (.*)\, but.*/
NOT_FOUND_GEM = /.*Could not find (.*) in any.*/
ADD_GEM_TO_GEMFILE = 1
def initialize
end
def run
@compwron
compwron / FuzzTest.java
Last active September 19, 2016 21:11
fuzzing an API given a swagger file (endpoint)
import com.google.common.collect.Lists;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.Parameter;
import io.swagger.parser.SwaggerParser;
import org.hamcrest.Matcher;