Skip to content

Commit

Permalink
Add tests for verifying equals and hashCode method + add threadsafe a…
Browse files Browse the repository at this point in the history
…nnotations
  • Loading branch information
aplotnikov committed Nov 3, 2018
1 parent 93af58b commit 8c21719
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 21 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ dependencies {
compile(
"io.projectreactor:reactor-core:${reactorVersion}",
'io.vavr:vavr:0.9.2',
'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.7'
'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.7',
'net.jcip:jcip-annotations:1.0'
)

testCompile(
'org.codehaus.groovy:groovy-all:2.5.3',
'org.spockframework:spock-core:1.2-groovy-2.5',
"io.projectreactor:reactor-test:${reactorVersion}",
'net.bytebuddy:byte-buddy:1.9.2',
'org.objenesis:objenesis:3.0.1'
'org.objenesis:objenesis:3.0.1',
'nl.jqno.equalsverifier:equalsverifier:3.0.2'
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.aplotnikov.batch.processing.reactor.entities.Response;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.ThreadSafe;

import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -13,6 +14,7 @@
import static java.util.concurrent.locks.LockSupport.parkNanos;
import static lombok.AccessLevel.PRIVATE;

@ThreadSafe
@FieldDefaults(level = PRIVATE, makeFinal = true)
@RequiredArgsConstructor
class ClientProcessor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.github.aplotnikov.batch.processing.reactor;

import io.github.aplotnikov.batch.processing.reactor.events.AbstractEvent;
import io.github.aplotnikov.batch.processing.reactor.events.ClientParsed;
import io.github.aplotnikov.batch.processing.reactor.events.ClientProcessed;
import io.github.aplotnikov.batch.processing.reactor.events.AbstractEvent;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.ThreadSafe;

import static io.vavr.API.$;
import static io.vavr.API.Case;
import static io.vavr.API.Match;
import static io.vavr.Predicates.instanceOf;
import static lombok.AccessLevel.PRIVATE;

@ThreadSafe
@FieldDefaults(level = PRIVATE, makeFinal = true)
@RequiredArgsConstructor
class EventProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import io.github.aplotnikov.batch.processing.reactor.entities.Response;
import io.github.aplotnikov.batch.processing.reactor.events.ClientProcessed;
import io.github.aplotnikov.batch.processing.reactor.events.AbstractEvent;
import io.github.aplotnikov.batch.processing.reactor.events.ClientProcessed;
import io.github.aplotnikov.batch.processing.reactor.events.FileProcessed;
import io.github.aplotnikov.batch.processing.reactor.events.FileProcessingStarted;
import io.vavr.control.Try;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.ThreadSafe;
import reactor.core.publisher.GroupedFlux;

import java.nio.file.Files;
Expand All @@ -21,6 +22,7 @@
import static java.nio.file.StandardOpenOption.APPEND;
import static lombok.AccessLevel.PRIVATE;

@ThreadSafe
@FieldDefaults(level = PRIVATE, makeFinal = true)
class EventWriter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import io.github.aplotnikov.batch.processing.reactor.source.EventSource;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.ThreadSafe;

import static lombok.AccessLevel.PRIVATE;

@ThreadSafe
@FieldDefaults(level = PRIVATE, makeFinal = true)
@RequiredArgsConstructor
class ReactorFileProcessor implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import lombok.Builder;
import lombok.Value;
import net.jcip.annotations.Immutable;

@Immutable
@Value
@Builder
public class Client {
public final class Client {

long id;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.aplotnikov.batch.processing.reactor.entities;

import lombok.Value;
import net.jcip.annotations.Immutable;

@Immutable
@Value
public class Response {
public final class Response {

long clientId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.Immutable;

import static lombok.AccessLevel.PRIVATE;

@Immutable
@FieldDefaults(level = PRIVATE, makeFinal = true)
@Getter
@ToString
@EqualsAndHashCode
public class ClientParsed extends AbstractEvent {
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public final class ClientParsed extends AbstractEvent {

Client client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.Immutable;

import static lombok.AccessLevel.PRIVATE;

@Immutable
@FieldDefaults(level = PRIVATE, makeFinal = true)
@Getter
@ToString
@EqualsAndHashCode
public class ClientProcessed extends AbstractEvent {
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public final class ClientProcessed extends AbstractEvent {

Response response;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.jcip.annotations.Immutable;

@ToString
@EqualsAndHashCode
public class FileProcessed extends AbstractEvent {
@Immutable
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public final class FileProcessed extends AbstractEvent {
public FileProcessed(String sourcePath) {
super(sourcePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.jcip.annotations.Immutable;

@ToString
@EqualsAndHashCode
public class FileProcessingStarted extends AbstractEvent {
@Immutable
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public final class FileProcessingStarted extends AbstractEvent {
public FileProcessingStarted(String sourcePath) {
super(sourcePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.jcip.annotations.Immutable;

@ToString
@EqualsAndHashCode
public class FileReceived extends AbstractEvent {
@Immutable
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public final class FileReceived extends AbstractEvent {
public FileReceived(String sourcePath) {
super(sourcePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.aplotnikov.batch.processing.reactor.events.FileProcessingStarted;
import io.vavr.control.Try;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.NotThreadSafe;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SynchronousSink;
Expand All @@ -28,6 +29,7 @@
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static lombok.AccessLevel.PRIVATE;

@NotThreadSafe
@FieldDefaults(level = PRIVATE)
public final class XmlFileReader implements FileReader {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.aplotnikov.batch.processing.reactor.readers;

import io.github.aplotnikov.batch.processing.reactor.events.AbstractEvent;
import net.jcip.annotations.ThreadSafe;
import reactor.core.publisher.Flux;

@ThreadSafe
public final class XmlFileReaderDecorator implements FileReader {
@Override
public Flux<AbstractEvent> read(AbstractEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import io.github.aplotnikov.batch.processing.reactor.events.AbstractEvent;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.ThreadSafe;
import reactor.core.publisher.Flux;

import static lombok.AccessLevel.PRIVATE;

@ThreadSafe
@FieldDefaults(level = PRIVATE, makeFinal = true)
@RequiredArgsConstructor
public class EventSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.aplotnikov.batch.processing.reactor.events.FileReceived;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.jcip.annotations.ThreadSafe;
import reactor.core.publisher.Flux;

import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -12,6 +13,7 @@
import static java.util.concurrent.locks.LockSupport.parkNanos;
import static lombok.AccessLevel.PRIVATE;

@ThreadSafe
@FieldDefaults(level = PRIVATE, makeFinal = true)
@RequiredArgsConstructor
class Source {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.aplotnikov.batch.processing.reactor.entities

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class ClientSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(Client)
.usingGetClass()
.verify()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.aplotnikov.batch.processing.reactor.entities

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class ResponseSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(Response)
.usingGetClass()
.verify()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.aplotnikov.batch.processing.reactor.events

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class ClientParsedSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(ClientParsed)
.usingGetClass()
.withRedefinedSuperclass()
.verify()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.aplotnikov.batch.processing.reactor.events

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class ClientProcessedSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(ClientProcessed)
.usingGetClass()
.withRedefinedSuperclass()
.verify()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.aplotnikov.batch.processing.reactor.events

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class FileProcessedSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(FileProcessed)
.usingGetClass()
.withRedefinedSuperclass()
.verify()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.aplotnikov.batch.processing.reactor.events

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class FileProcessingStartedSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(FileProcessingStarted)
.usingGetClass()
.withRedefinedSuperclass()
.verify()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.aplotnikov.batch.processing.reactor.events

import nl.jqno.equalsverifier.EqualsVerifier
import spock.lang.Specification

class FileReceivedSpec extends Specification {
void 'equals and hashcode contract should be followed'() {
expect:
EqualsVerifier.forClass(FileReceived)
.usingGetClass()
.withRedefinedSuperclass()
.verify()
}
}

0 comments on commit 8c21719

Please sign in to comment.