Skip to content
Snippets Groups Projects
Unverified Commit c29ab65e authored by Peter Kurfer's avatar Peter Kurfer
Browse files

Ported to Java 11 to use type inference

parent 83169162
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ public abstract class App {
private static final JokeGenerator jokeGenerator = new JokeGenerator();
public static void main(String[] args) {
boolean shouldQuit = false;
var shouldQuit = false;
int jokeCount;
int skipCount;
......@@ -38,7 +38,7 @@ public abstract class App {
* and print the jokes to the STDOUT */
System.out.println("If you want to quit press [Q] otherwise press [C] to continue.");
String input = inputScanner.next();
var input = inputScanner.next();
if (input.equals("q") || input.equals("Q")) {
shouldQuit = true;
}
......@@ -57,7 +57,7 @@ public abstract class App {
System.out.println(message);
do {
try {
int input = inputScanner.nextInt();
var input = inputScanner.nextInt();
if (input >= 0) return input;
} catch (Exception e) {
System.out.println("Error while reading integer.");
......@@ -77,7 +77,7 @@ public abstract class App {
do {
try {
int selection = inputScanner.nextInt();
var selection = inputScanner.nextInt();
switch (selection) {
case 1:
return jokeGenerator.randomJokesStream();
......
......@@ -34,7 +34,7 @@ public final class ICNDBService implements ICNDBApi {
private ICNDBService() {
/* Initialize Retrofit */
Retrofit retrofit = new Retrofit.Builder()
var retrofit = new Retrofit.Builder()
.baseUrl("http://api.icndb.com")
.addConverterFactory(GsonConverterFactory.create())
/* CallAdapterFactory required to wrap calls in CompletableFutures */
......
......@@ -63,7 +63,7 @@ public class JokeDto {
if (!(o instanceof JokeDto)) return false;
JokeDto joke1 = (JokeDto) o;
var joke1 = (JokeDto) o;
return new EqualsBuilder()
.append(getId(), joke1.getId())
......
......@@ -53,7 +53,7 @@ public class ResponseWrapper<T> {
if (!(o instanceof ResponseWrapper)) return false;
ResponseWrapper<?> that = (ResponseWrapper<?>) o;
var that = (ResponseWrapper<?>) o;
return new EqualsBuilder()
.append(getType(), that.getType())
......
package de.thro.inf.prg3.a12.icndb;
import de.thro.inf.prg3.a12.model.JokeDto;
import de.thro.inf.prg3.a12.model.ResponseWrapper;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
......@@ -30,13 +25,13 @@ public class ICNDBTests {
@Test
void testCollision() throws ExecutionException, InterruptedException {
Set<Integer> jokeNumbers = new HashSet<>();
int requests = 0;
boolean collision = false;
var jokeNumbers = new HashSet<>();
var requests = 0;
var collision = false;
while (requests++ < REQUEST_COUNT) {
CompletableFuture<ResponseWrapper<JokeDto>> jokeCall = icndbApi.getRandomJoke();
JokeDto joke = jokeCall.get().getValue();
var jokeCall = icndbApi.getRandomJoke();
var joke = jokeCall.get().getValue();
if (jokeNumbers.contains(joke.getId())) {
logger.info(String.format("Collision at joke %s", joke.getId()));
......@@ -53,7 +48,7 @@ public class ICNDBTests {
@Test
void testGetRandomJokeWithChangedName() throws ExecutionException, InterruptedException {
JokeDto j = icndbApi.getRandomJoke("Bruce", "Wayne").get().getValue();
var j = icndbApi.getRandomJoke("Bruce", "Wayne").get().getValue();
assertNotNull(j);
assertFalse(j.getJoke().contains("Chuck"));
assertFalse(j.getJoke().contains("Norris"));
......@@ -63,14 +58,14 @@ public class ICNDBTests {
@Test
void testGetJokeById() throws ExecutionException, InterruptedException {
List<Integer> randomIds = new ArrayList<>(10);
var randomIds = new ArrayList<Integer>(10);
for(int i = 0; i < 10; i++) {
for (var i = 0; i < 10; i++) {
randomIds.add(icndbApi.getRandomJoke().get().getValue().getId());
}
for(Integer id : randomIds) {
JokeDto j = icndbApi.getJoke(id).get().getValue();
for (var id : randomIds) {
var j = icndbApi.getJoke(id).get().getValue();
assertNotNull(j);
assertTrue(randomIds.contains(j.getId()));
logger.info(j.toString());
......@@ -79,7 +74,7 @@ public class ICNDBTests {
@Test
void testGetJokeCount() throws ExecutionException, InterruptedException {
int jokeCount = icndbApi.getJokeCount().get().getValue();
var jokeCount = icndbApi.getJokeCount().get().getValue();
assertNotEquals(0, jokeCount);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment