/*
 * Copyright (c) 2015  Sebastian Paarmann
 * Licensed under the MIT license, see the LICENSE file
 */

/**
 * Created by basti on 26.09.15.
 */
package paarmann.physikprofil.test;

import org.junit.Test;

import paarmann.physikprofil.HAElement;

import static org.junit.Assert.*;

public class HAElementTest {

  private HAElement createElement(int id, String date, String title,
                                  String subject, String desc) {
    HAElement e = new HAElement();
    e.id = id;
    e.date = date;
    e.title = title;
    e.subject = subject;
    e.desc = desc;
    return e;
  }

  @Test
  public void testCreateSingleFromString()
  {
    HAElement actual = HAElement.createSingleFromString(
        "42~2015-01-01~Some Homework~testing~This is a test item");
    HAElement expected = createElement(42, "2015-01-01", "Some Homework",
        "testing", "This is a test item");

    assertEquals(expected, actual);
  }

  @Test
  public void testCreateFromSsp()
  {
    String ssp = "1~2015-01-01~Test 1~testing~A test item\\"
        + "2~2015-01-02~Test 2~testing~Another test item";
    HAElement[] actual = HAElement.createFromSsp(ssp)
      .toArray(new HAElement[2]);
    HAElement[] expected = {
        createElement(1, "2015-01-01", "Test 1", "testing", "A test item"),
        createElement(2, "2015-01-02", "Test 2", "testing", "Another test item")
    };
    assertArrayEquals(expected, actual);
  }

  @Test
  public void testGetSsp() {
    String actual = createElement(1, "2015-01-01", "Test", "testing", "Test")
        .getSsp();
    String expected = "1~2015-01-01~Test~testing~Test";
    assertEquals(expected, actual);
  }
}

@@ -345,11 +345,14 @@
 ent(
+Str
 in
-t
+g
  id,
@@ -816,18 +816,20 @@
 Element(
+%22
 42
+%22
 , %222015-
@@ -1235,33 +1235,35 @@
   createElement(
-1
+%221%22
 , %222015-01-01%22, 
@@ -1321,17 +1321,19 @@
 Element(
-2
+%222%22
 , %222015-
@@ -1506,17 +1506,19 @@
 Element(
-1
+%221%22
 , %222015-

Fix HAElement tests