Skip to content

Commit

Permalink
added automatic tests for constructor with generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Michail Plushnikov committed Mar 25, 2016
1 parent 12a1686 commit b7c8c86
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 168 deletions.
8 changes: 8 additions & 0 deletions src/test/java/de/plushnikov/lombok/tests/ConstructorTest.java
Expand Up @@ -24,4 +24,12 @@ public void testNoArgsConstructorForced() throws IOException {
public void testConstructorEnum() throws IOException {
doTest();
}

public void testRequiredArgsConstructorWithGeneric136() throws IOException {
doTest();
}

public void testRequiredArgsConstructorWithGeneric157() throws IOException {
doTest();
}
}
30 changes: 0 additions & 30 deletions test-manual/src/main/java/de/plushnikov/constructor/Issue136.java

This file was deleted.

33 changes: 0 additions & 33 deletions test-manual/src/main/java/de/plushnikov/constructor/Issue157.java

This file was deleted.

@@ -0,0 +1,33 @@
package de.plushnikov.constructor;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

public class RequiredArgsConstructorWithGeneric136<T> {

@Getter
@RequiredArgsConstructor(staticName = "of2")
private static class Foo<T> {
private final T object;
private final int i;

static <T> Foo<T> of(T object, int i) {
return new Foo<T>(object, i);
}
}

private <D> Foo<D> createFoo(D t, int i) {
return new Foo<>(t, i);
}

public static void main(String[] args) {
Foo<String> stringFoo = new Foo<>("", 2);

Foo<String> foo1 = Foo.of("String2", 123);
Foo<String> foo2 = Foo.of2("String2", 4423);

System.out.println(stringFoo);
System.out.println(foo1);
System.out.println(foo2);
}
}
@@ -0,0 +1,31 @@
package de.plushnikov.constructor;

import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.Map;

public class RequiredArgsConstructorWithGeneric157 {

@RequiredArgsConstructor(staticName = "of")
private static class Foo<T, E extends Exception> {
private final Map<T, E> bar;

Map<T, E> buildBar() {
return bar;
}
}

public static void main(String[] args) {
Foo<String, IllegalArgumentException> foo = new Foo<>(new HashMap<String, IllegalArgumentException>());
System.out.println(foo);

HashMap<Integer, IllegalStateException> hashMap = new HashMap<>();
Foo<Integer, IllegalStateException> myFoo = Foo.of(hashMap);
Map<Integer, IllegalStateException> bar = myFoo.buildBar();
System.out.println(bar);

Foo<Integer, NullPointerException> exceptionFoo = Foo.of(new HashMap<Integer, NullPointerException>());
System.out.println(exceptionFoo.buildBar());
}
}
@@ -1,53 +1,52 @@
package de.plushnikov.delegate.issue88;

import lombok.experimental.Delegate;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;

public class DelegateGenericInterfaceIssue88 {
public <T> T visit(T object) {
return this.visitor.visit(object);
}

interface Visitor88 {
<T> T visit(T object);
}

private static class Visitor88Impl implements Visitor88 {
@Override
public <T> T visit(T object) {
System.out.println("Lets see what we got: " + object.getClass());
return object;

interface Visitor88 {
<T> T visit(T object);
}

private static class Visitor88Impl implements Visitor88 {
@Override
public <T> T visit(T object) {
System.out.println("Lets see what we got: " + object.getClass());
return object;
}
}

private static class MyWorker88 {
String doWork() {
return "The Work Was done";
}
}

@Delegate
private Visitor88 visitor = new Visitor88Impl();

private MyWorker88 myWorker;

@Before
public void setUp() throws Exception {
myWorker = new MyWorker88();
}

@Test
public void testDoWorkWithDelegation() throws Exception {
String work = visit(myWorker).doWork();
assertNotNull(work);
System.out.println("testDoWorkWithDelegation - Work:" + work);
}
}

private static class MyWorker88 {
String doWork() {
return "The Work Was done";
@Test
public void testDoWorkWithoutDelegation() throws Exception {
String work = visitor.visit(myWorker).doWork();
assertNotNull(work);
System.out.println("testDoWorkWithoutDelegation - Work: " + work);
}
}

private Visitor88 visitor = new Visitor88Impl();

private MyWorker88 myWorker;

@Before
public void setUp() throws Exception {
myWorker = new MyWorker88();
}

@Test
public void testDoWorkWithDelegation() throws Exception {
String work = visit(myWorker).doWork();
assertNotNull(work);
System.out.println("testDoWorkWithDelegation - Work:" + work);
}

@Test
public void testDoWorkWithoutDelegation() throws Exception {
String work = visitor.visit(myWorker).doWork();
assertNotNull(work);
System.out.println("testDoWorkWithoutDelegation - Work: " + work);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

43 changes: 43 additions & 0 deletions testData/after/RequiredArgsConstructorWithGeneric136.java
@@ -0,0 +1,43 @@
public class RequiredArgsConstructorWithGeneric136<T> {

private static class Foo<T> {
private final T object;
private final int i;

private Foo(T object, int i) {
this.object = object;
this.i = i;
}

static <T> Foo<T> of(T object, int i) {
return new Foo<T>(object, i);
}

public static <T> Foo<T> of2(T object, int i) {
return new Foo<T>(object, i);
}

public T getObject() {
return this.object;
}

public int getI() {
return this.i;
}
}

private <D> Foo<D> createFoo(D t, int i) {
return new Foo<>(t, i);
}

public static void main(String[] args) {
Foo<String> stringFoo = new Foo<>("", 2);

Foo<String> foo1 = Foo.of("String2", 123);
Foo<String> foo2 = Foo.of2("String2", 4423);

System.out.println(stringFoo);
System.out.println(foo1);
System.out.println(foo2);
}
}
34 changes: 34 additions & 0 deletions testData/after/RequiredArgsConstructorWithGeneric157.java
@@ -0,0 +1,34 @@
import java.util.HashMap;
import java.util.Map;

public class RequiredArgsConstructorWithGeneric157 {

private static class Foo<T, E extends Exception> {
private final Map<T, E> bar;

private Foo(Map<T, E> bar) {
this.bar = bar;
}

public static <T, E extends Exception> Foo<T, E> of(Map<T, E> bar) {
return new Foo<T, E>(bar);
}

Map<T, E> buildBar() {
return bar;
}
}

public static void main(String[] args) {
Foo<String, IllegalArgumentException> foo = new Foo<>(new HashMap<String, IllegalArgumentException>());
System.out.println(foo);

HashMap<Integer, IllegalStateException> hashMap = new HashMap<>();
Foo<Integer, IllegalStateException> myFoo = Foo.of(hashMap);
Map<Integer, IllegalStateException> bar = myFoo.buildBar();
System.out.println(bar);

Foo<Integer, NullPointerException> exceptionFoo = Foo.of(new HashMap<Integer, NullPointerException>());
System.out.println(exceptionFoo.buildBar());
}
}

0 comments on commit b7c8c86

Please sign in to comment.