Skip to content

Instantly share code, notes, and snippets.

@aspineon
aspineon / ProgrammableTest.java
Created March 15, 2018 06:19 — forked from greghelton/ProgrammableTest.java
Java: Using Mockito for Unit Testing
package us.home.electronics;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
public class ProgrammableTest {
package com.example.tdd;
import java.math.BigDecimal;
public class UtilizationController {
private CalculatesAverage calculatesAverage;
private CountsHoursInMonth countsHoursInMonth;
private AccumulatesActualsInMonth accumulatesActualsInMonth;
import static org.apache.avro.Schema.Type.DOUBLE;
import static org.apache.avro.Schema.Type.FLOAT;
import static org.apache.avro.Schema.Type.INT;
import static org.apache.avro.Schema.Type.LONG;
import static org.apache.avro.Schema.Type.NULL;
import static org.apache.avro.Schema.Type.STRING;
import static org.apache.avro.Schema.Type.UNION;
import java.util.Arrays;
import java.util.LinkedHashMap;
@aspineon
aspineon / DefaultMethods.java
Created July 31, 2018 18:52 — forked from shelajev/DefaultMethods.java
Java 8 Cheat Sheet Code Snippets
//Default methods in interfaces
@FunctionalInterface
interface Utilities {
default Consumer<Runnable> m() {
return (r) -> r.run();
}
// default methods, still functional
Object function(Object o);
}
@aspineon
aspineon / java8.txt
Created July 31, 2018 18:52 — forked from mit09/java8.txt
Java8 & collections cheat sheet
Set:
ImmutableSet.of(element1, element2, ..) from com.google.common.collect.ImmutableSet;
Compare:
Long.compare(long1, long2)
Equals:
Object.equal
Object.hashCode
@aspineon
aspineon / SomePojoValidatorTest.java
Created August 16, 2018 04:16 — forked from Christopher-Barham-AKQA/SomePojoValidatorTest.java
SomePojoValidatorTest.java unit test for Hibernate Validator
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.Locale;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
@aspineon
aspineon / README-bean-validation.md
Created August 16, 2018 04:30 — forked from drmalex07/README-bean-validation.md
Example with bean validation. #bean-validation #java #validation

README

First, we need to download an implementation for bean validation JSR. We use hibernate-validator for this, so we must include something like the following inside POM (see also http://hibernate.org/validator/documentation/getting-started/):

<!-- Bean validation -->

    <dependency>
        <groupId>org.hibernate</groupId>
@aspineon
aspineon / gist:82fe84319efc74807330d294de3caf2e
Created August 16, 2018 04:32 — forked from roalcantara/gist:2342555
JAVA > Hibernate > Custom Validator Simple Sample
package com.xpto.domain.model.validator;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = PhotoExtensionValidator.class)
@Documented
## Register driver
ARCHIVE_NAME=ojdbc6.jar
REPOSITORY_DIR=pathToDriver
SERVER_DIR=pathToWildfly
INSTALL_DIR=$SERVER_DIR/modules/system/layers/base/com/oracle/ojdbc6/main
SERVER_USER=petr
SERVER_PASSW=petr
mkdir -p $INSTALL_DIR
cp $REPOSITORY_DIR/$ARCHIVE_NAME $INSTALL_DIR
@aspineon
aspineon / note.md
Created October 2, 2018 19:31 — forked from ChrisKujawa/note.md
Oracle with Jboss 7

Oracle

Run for example docker image

Jboss configuration

As first create model directory and add module.xml

$ mkdir -p server/jboss-as-7.2.0.Final/modules/com/oracle/jdbc/ojdbc14/main/ $ vim server/jboss-as-7.2.0.Final/modules/com/oracle/jdbc/ojdbc14/main/module.xml

Could look like this: