Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
added tests
  • Loading branch information
olech2412 committed Feb 20, 2024
1 parent 8fe3737 commit f312b6d
Show file tree
Hide file tree
Showing 13 changed files with 776 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class APIConfiguration {

@Setter
private Proxy proxy;

public APIConfiguration() {
buildRequestList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private Request getRequest(RequestPath requestPath) {

/**
* Perform the request
*
* @param request the request
* @return the result of the request
* @throws IOException if the request fails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
public enum Mode {
BUS, TAXI, WATERCRAFT, TRAIN;

public String toValue() {
switch (this) {
case BUS: return "bus";
case TAXI: return "taxi";
case WATERCRAFT: return "watercraft";
case TRAIN: return "train";
}
return null;
}

public static Mode forValue(String value) throws IOException {
if (value.equals("bus")) return BUS;
if (value.equals("taxi")) return TAXI;
Expand All @@ -32,6 +22,20 @@ public static Mode forValue(String value) throws IOException {
throw new IOException("Cannot deserialize Mode");
}

public String toValue() {
switch (this) {
case BUS:
return "bus";
case TAXI:
return "taxi";
case WATERCRAFT:
return "watercraft";
case TRAIN:
return "train";
}
return null;
}

// custom ModeTypeAdapter for gson
public static class ModeTypeAdapter extends TypeAdapter<Mode> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.olech2412.adapter.dbadapter.exception;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ErrorTest {

@Test
void creatingErrorShouldSetMessageAndCode() {
String message = "Error Message";
int code = 404;
Error error = new Error() {
@Override
public String getMessage() {
return message;
}

@Override
public int getCode() {
return code;
}
};

assertEquals(message, error.getMessage());
assertEquals(code, error.getCode());
}

@Test
void getErrorShouldReturnFormattedErrorMessage() {
String message = "Error Message";
int code = 404;
Error error = new Error() {
@Override
public String getMessage() {
return message;
}

@Override
public int getCode() {
return code;
}
};

String expected = "404: Error Message";
assertEquals(expected, error.getError());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package de.olech2412.adapter.dbadapter.model.journey;

import de.olech2412.adapter.dbadapter.model.journey.sub.Leg;
import de.olech2412.adapter.dbadapter.model.journey.sub.Price;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class JourneyTest {
private Journey journey;

@BeforeEach
void setUp() {
journey = new Journey();
}

@Test
void shouldSetAndGetType() {
String expectedType = "TestType";
journey.setType(expectedType);
assertEquals(expectedType, journey.getType());
}

@Test
void shouldSetAndGetTypeWhenTypeIsNull() {
journey.setType(null);
assertNull(journey.getType());
}

@Test
void shouldSetAndGetLegs() {
Leg expectedLeg = new Leg();
journey.setLegs(Collections.singletonList(expectedLeg));
assertEquals(Collections.singletonList(expectedLeg), journey.getLegs());
}

@Test
void shouldSetAndGetLegsWhenLegsIsNull() {
journey.setLegs(null);
assertNull(journey.getLegs());
}

@Test
void shouldSetAndGetRefreshToken() {
String expectedRefreshToken = "TestRefreshToken";
journey.setRefreshToken(expectedRefreshToken);
assertEquals(expectedRefreshToken, journey.getRefreshToken());
}

@Test
void shouldSetAndGetRefreshTokenWhenRefreshTokenIsNull() {
journey.setRefreshToken(null);
assertNull(journey.getRefreshToken());
}

@Test
void shouldSetAndGetPrice() {
Price expectedPrice = new Price();
journey.setPrice(expectedPrice);
assertEquals(expectedPrice, journey.getPrice());
}

@Test
void shouldSetAndGetPriceWhenPriceIsNull() {
journey.setPrice(null);
assertNull(journey.getPrice());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class FeatureTest {
private Feature feature;

@BeforeEach
void setUp() {
feature = new Feature();
}

@Test
void shouldSetAndGetType() {
String expectedType = "TestType";
feature.setType(expectedType);
assertEquals(expectedType, feature.getType());
}

@Test
void shouldSetAndGetTypeWhenTypeIsNull() {
feature.setType(null);
assertNull(feature.getType());
}

@Test
void shouldSetAndGetProperties() {
Properties expectedProperties = new Properties();
feature.setProperties(expectedProperties);
assertEquals(expectedProperties, feature.getProperties());
}

@Test
void shouldSetAndGetPropertiesWhenPropertiesIsNull() {
feature.setProperties(null);
assertNull(feature.getProperties());
}

@Test
void shouldSetAndGetGeometry() {
Geometry expectedGeometry = new Geometry();
feature.setGeometry(expectedGeometry);
assertEquals(expectedGeometry, feature.getGeometry());
}

@Test
void shouldSetAndGetGeometryWhenGeometryIsNull() {
feature.setGeometry(null);
assertNull(feature.getGeometry());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

public class GeometryTest {
private Geometry geometry;

@BeforeEach
void setUp() {
geometry = new Geometry();
}

@Test
void shouldSetAndGetType() {
String expectedType = "Point";
geometry.setType(expectedType);
assertEquals(expectedType, geometry.getType());
}

@Test
void shouldSetAndGetTypeWhenTypeIsNull() {
geometry.setType(null);
assertNull(geometry.getType());
}

@Test
void shouldSetAndGetCoordinates() {
List<Double> expectedCoordinates = Arrays.asList(1.0, 2.0);
geometry.setCoordinates(expectedCoordinates);
assertEquals(expectedCoordinates, geometry.getCoordinates());
}

@Test
void shouldSetAndGetCoordinatesWhenCoordinatesIsNull() {
geometry.setCoordinates(null);
assertNull(geometry.getCoordinates());
}

@Test
void shouldSetAndGetCoordinatesWhenCoordinatesIsEmpty() {
geometry.setCoordinates(new ArrayList<>());
assertTrue(geometry.getCoordinates().isEmpty());
}
}
Loading

0 comments on commit f312b6d

Please sign in to comment.