Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added automatic tests for constructor with generics
- Loading branch information
Michail Plushnikov
committed
Mar 25, 2016
1 parent
12a1686
commit b7c8c86
Showing
14 changed files
with
249 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
test-manual/src/main/java/de/plushnikov/constructor/Issue136.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
test-manual/src/main/java/de/plushnikov/constructor/Issue157.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...manual/src/main/java/de/plushnikov/constructor/RequiredArgsConstructorWithGeneric136.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...manual/src/main/java/de/plushnikov/constructor/RequiredArgsConstructorWithGeneric157.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
81 changes: 40 additions & 41 deletions
81
...-manual/src/main/java/de/plushnikov/delegate/issue88/DelegateGenericInterfaceIssue88.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
test-manual/src/main/java/de/plushnikov/delegate/issue88/MyWorkerTest.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
test-manual/src/main/java/de/plushnikov/delegate/issue88/visitor/Visitor.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
test-manual/src/main/java/de/plushnikov/delegate/issue88/visitor/impl/VisitorImpl.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test-manual/src/main/java/de/plushnikov/delegate/issue88/worker/MyWorker.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
Oops, something went wrong.