// Path: api/src/main/java/ch/liip/timeforcoffee/api/deserializers/DateDeserializer.java
// public class DateDeserializer implements JsonDeserializer<Date> {
// 
//   private final String[] DATE_FORMATS = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ssZ" };
// 
//   @Override
//   public Date deserialize(JsonElement jsonElement, Type typeOF, JsonDeserializationContext context) throws JsonParseException {
//     for (String format : DATE_FORMATS) {
//       try {
//         return new SimpleDateFormat(format).parse(jsonElement.getAsString());
//       } catch (ParseException e) { }
//     }
// 
//     throw new JsonParseException("Unparseable date: \"" + jsonElement.getAsString() + "\". Supported formats: " + Arrays.toString(DATE_FORMATS));
//   }
// }
// 
// Path: backend/src/main/java/ch/liip/timeforcoffee/backend/Connection.java
// public class Connection {
// 
//     private int id;
//     private String name;
//     private ConnectionLocation location;
//     private Time departure;
//     private Time arrival;
// 
//     public Connection() {}
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public ConnectionLocation getLocation() {
//         return location;
//     }
// 
//     public Time getDeparture() { return departure; }
// 
//     public Time getArrival() { return arrival; }
// }
// 
// Path: backend/src/main/java/ch/liip/timeforcoffee/backend/Connections.java
// public class Connections {
// 
//     private List<List<Connection>> passlist;
// 
//     public Connections() {}
// 
//     public List<List<Connection>> getConnections() {
//         return passlist;
//     }
// }


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Test;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import ch.liip.timeforcoffee.api.deserializers.DateDeserializer;
import ch.liip.timeforcoffee.backend.Connection;
import ch.liip.timeforcoffee.backend.Connections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
package ch.liip.timeforcoffee.api;






public class ConnectionDeserializationTest {

    private final SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    private final Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class, new DateDeserializer())
            .create();

    @Test
    public void connectionsDeserialization_Works() throws UnsupportedEncodingException {
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("connections.json");
        InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);

        Connections connections = gson.fromJson(reader, Connections.class);

        assertEquals(1, connections.getConnections().size());
// Path: api/src/main/java/ch/liip/timeforcoffee/api/deserializers/DateDeserializer.java
// public class DateDeserializer implements JsonDeserializer<Date> {
// 
//   private final String[] DATE_FORMATS = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ssZ" };
// 
//   @Override
//   public Date deserialize(JsonElement jsonElement, Type typeOF, JsonDeserializationContext context) throws JsonParseException {
//     for (String format : DATE_FORMATS) {
//       try {
//         return new SimpleDateFormat(format).parse(jsonElement.getAsString());
//       } catch (ParseException e) { }
//     }
// 
//     throw new JsonParseException("Unparseable date: \"" + jsonElement.getAsString() + "\". Supported formats: " + Arrays.toString(DATE_FORMATS));
//   }
// }
// 
// Path: backend/src/main/java/ch/liip/timeforcoffee/backend/Connection.java
// public class Connection {
// 
//     private int id;
//     private String name;
//     private ConnectionLocation location;
//     private Time departure;
//     private Time arrival;
// 
//     public Connection() {}
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public ConnectionLocation getLocation() {
//         return location;
//     }
// 
//     public Time getDeparture() { return departure; }
// 
//     public Time getArrival() { return arrival; }
// }
// 
// Path: backend/src/main/java/ch/liip/timeforcoffee/backend/Connections.java
// public class Connections {
// 
//     private List<List<Connection>> passlist;
// 
//     public Connections() {}
// 
//     public List<List<Connection>> getConnections() {
//         return passlist;
//     }
// }


// Path: api/src/test/java/ch/liip/timeforcoffee/api/ConnectionDeserializationTest.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Test;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import ch.liip.timeforcoffee.api.deserializers.DateDeserializer;
import ch.liip.timeforcoffee.backend.Connection;
import ch.liip.timeforcoffee.backend.Connections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

package ch.liip.timeforcoffee.api;






public class ConnectionDeserializationTest {

    private final SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    private final Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class, new DateDeserializer())
            .create();

    @Test
    public void connectionsDeserialization_Works() throws UnsupportedEncodingException {
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("connections.json");
        InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);

        Connections connections = gson.fromJson(reader, Connections.class);

        assertEquals(1, connections.getConnections().size());
        assertEquals(5, connections.getConnections().get(0).size());