Skip to content

Commit

Permalink
minor code clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Aug 30, 2022
1 parent a910059 commit 0ee348e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ steps:
- name: test
image: maven:3-openjdk-8
commands:
- mvn clean test
- mvn -B clean test

---
kind: pipeline
Expand All @@ -17,7 +17,7 @@ steps:
- name: test
image: maven:3-openjdk-11
commands:
- mvn clean test
- mvn -B clean test

---
kind: pipeline
Expand All @@ -28,4 +28,4 @@ steps:
- name: test
image: maven:3-openjdk-17
commands:
- mvn clean test
- mvn -B clean test
6 changes: 3 additions & 3 deletions src/main/java/de/stklcode/pubtrans/ura/UraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public List<Trip> getTrips(final Query query, final Integer limit) {
String version = null;
String line = br.readLine();
while (line != null && (limit == null || trips.size() < limit)) {
List l = mapper.readValue(line, List.class);
List<?> l = mapper.readValue(line, List.class);
/* Check if result exists and has correct response type */
if (l != null && !l.isEmpty()) {
if (l.get(0).equals(RES_TYPE_URA_VERSION)) {
Expand Down Expand Up @@ -311,7 +311,7 @@ public List<Stop> getStops(final Query query) {
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = br.readLine()) != null) {
List l = mapper.readValue(line, List.class);
List<?> l = mapper.readValue(line, List.class);
/* Check if result exists and has correct response type */
if (l != null && !l.isEmpty() && l.get(0).equals(RES_TYPE_STOP)) {
stops.add(new Stop(l));
Expand Down Expand Up @@ -361,7 +361,7 @@ public List<Message> getMessages(final Query query, final Integer limit) {
String version = null;
String line = br.readLine();
while (line != null && (limit == null || messages.size() < limit)) {
List l = mapper.readValue(line, List.class);
List<?> l = mapper.readValue(line, List.class);
/* Check if result exists and has correct response type */
if (l != null && !l.isEmpty()) {
if (l.get(0).equals(RES_TYPE_URA_VERSION)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/stklcode/pubtrans/ura/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Message(final Stop stop,
* @param raw List of attributes from JSON line
* @throws IOException Thrown on invalid line format.
*/
public Message(final List raw) throws IOException {
public Message(final List<?> raw) throws IOException {
this(raw, null);
}

Expand All @@ -98,7 +98,7 @@ public Message(final List raw) throws IOException {
* @param version API version
* @throws IOException Thrown on invalid line format.
*/
public Message(final List raw, final String version) throws IOException {
public Message(final List<?> raw, final String version) throws IOException {
if (raw == null || raw.size() < NUM_OF_FIELDS) {
throw new IOException("Invalid number of fields");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/stklcode/pubtrans/ura/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Model extends Serializable {
* @param actual Actual class.
* @return The Exception.
*/
static IOException typeErrorString(int field, Class actual) {
static IOException typeErrorString(int field, Class<?> actual) {
return typeError(field, actual, "String");
}

Expand All @@ -45,7 +45,7 @@ static IOException typeErrorString(int field, Class actual) {
* @param expected Expected type.
* @return The Exception.
*/
static IOException typeError(int field, Class actual, String expected) {
static IOException typeError(int field, Class<?> actual, String expected) {
return new IOException(String.format("Field %d not of expected type %s, found %s",
field, expected, actual.getSimpleName()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/stklcode/pubtrans/ura/model/Stop.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Stop(final String id,
* @param raw List of attributes from JSON line
* @throws IOException Thrown on invalid line format.
*/
public Stop(final List raw) throws IOException {
public Stop(final List<?> raw) throws IOException {
if (raw == null || raw.size() < F_NUM_OF_FIELDS) {
throw new IOException("Invalid number of fields");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/stklcode/pubtrans/ura/model/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Trip(final Stop stop,
* @param raw List of attributes from JSON line
* @throws IOException Thrown on invalid line format.
*/
public Trip(final List raw) throws IOException {
public Trip(final List<?> raw) throws IOException {
this(raw, null);
}

Expand All @@ -153,7 +153,7 @@ public Trip(final List raw) throws IOException {
* @param version API version
* @throws IOException Thrown on invalid line format.
*/
public Trip(final List raw, final String version) throws IOException {
public Trip(final List<?> raw, final String version) throws IOException {
if (raw == null || raw.size() < NUM_OF_FIELDS) {
throw new IOException("Invalid number of fields");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void open() {
String version = null;
String line = br.readLine();
while (line != null && !this.canceled) {
List l = mapper.readValue(line, List.class);
List<?> l = mapper.readValue(line, List.class);
// Check if result exists and has correct response type.
if (l != null && !l.isEmpty()) {
if (l.get(0).equals(RES_TYPE_URA_VERSION)) {
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@
*
* @author Stefan Kalscheuer
*/
public class UraClientTest {
class UraClientTest {
private static WireMockServer httpMock;

@BeforeAll
public static void setUp() {
static void setUp() {
// Initialize HTTP mock.
httpMock = new WireMockServer(WireMockConfiguration.options().dynamicPort());
httpMock.start();
WireMock.configureFor("localhost", httpMock.port());
}

@AfterAll
public static void tearDown() {
static void tearDown() {
httpMock.stop();
httpMock = null;
}

@Test
public void getStopsTest() {
void getStopsTest() {
// Mock the HTTP call.
mockHttpToFile(2, "instant_V2_stops.txt");

Expand All @@ -89,7 +89,7 @@ public void getStopsTest() {
}

@Test
public void getStopsForLineTest() {
void getStopsForLineTest() {
// Mock the HTTP call.
mockHttpToFile(2, "instant_V2_stops_line.txt");

Expand All @@ -107,7 +107,7 @@ public void getStopsForLineTest() {
}

@Test
public void getStopsForPositionTest() {
void getStopsForPositionTest() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_stops_circle.txt");

Expand All @@ -133,7 +133,7 @@ public void getStopsForPositionTest() {
}

@Test
public void getTripsForDestinationNamesTest() {
void getTripsForDestinationNamesTest() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_destination.txt");

Expand All @@ -156,7 +156,7 @@ public void getTripsForDestinationNamesTest() {
}

@Test
public void getTripsTowardsTest() {
void getTripsTowardsTest() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_towards.txt");

Expand All @@ -171,7 +171,7 @@ public void getTripsTowardsTest() {
}

@Test
public void getTripsTest() {
void getTripsTest() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_all.txt");

Expand Down Expand Up @@ -224,7 +224,7 @@ public void getTripsTest() {
}

@Test
public void getTripsForStopTest() {
void getTripsForStopTest() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_stop.txt");

Expand Down Expand Up @@ -254,7 +254,7 @@ public void getTripsForStopTest() {
}

@Test
public void getTripsForLine() {
void getTripsForLine() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_line.txt");

Expand Down Expand Up @@ -303,7 +303,7 @@ public void getTripsForLine() {
}

@Test
public void getTripsForStopAndLine() {
void getTripsForStopAndLine() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_stop_line.txt");

Expand All @@ -324,7 +324,7 @@ public void getTripsForStopAndLine() {


@Test
public void getMessages() {
void getMessages() {
// Mock the HTTP call.
mockHttpToFile(1, "instant_V1_messages.txt");

Expand All @@ -343,7 +343,7 @@ public void getMessages() {
}

@Test
public void getMessagesForStop() {
void getMessagesForStop() {
// Mock the HTTP call.
mockHttpToFile(2, "instant_V2_messages_stop.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void readerTest() throws InterruptedException, IOException {
* @throws IOException Error reading or writing mocked data.
*/
@Test
public void streamClosedTest() throws InterruptedException, IOException {
void streamClosedTest() throws InterruptedException, IOException {
// Callback counter for some unhandy async mockery.
final AtomicInteger counter = new AtomicInteger(0);

Expand Down

0 comments on commit 0ee348e

Please sign in to comment.