package iptc.common.builder;

/*
 * #%L
 * IPTC NewsML G2 Model
 * %%
 * Copyright (C) 2015 Ben Asmussen <opensource@ben-asmussen.com>
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import static iptc.common.builder.CalendarBuilder.calendar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

import org.junit.Test;

public class CalendarBuilderTest
{

    @Test
    public void testCalendarBuilder() throws Exception
    {
        Calendar cal = calendar().build();
        assertNotNull(cal);
    }

    @Test
    public void testCalendarTimeZoneAndLocale() throws Exception
    {
        Calendar cal = calendar().timzone("Europe/Berlin").locale(Locale.GERMAN).build();
        assertNotNull(cal);
        assertEquals("Europe/Berlin", cal.getTimeZone().getID());
    }

    @Test
    public void testDate() throws Exception
    {
        Calendar cal = calendar().timzone("Europe/Berlin").locale(Locale.GERMAN).date("2015-01-01").build();

        SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
        sdf.setCalendar(cal);
        String format = sdf.format(cal.getTime());

        assertEquals("Mo, 29 Dez 2014 00:00:00 +0100", format);
    }

    @Test
    public void testDateAndTime() throws Exception
    {
        Calendar cal = calendar().timzone("Europe/Berlin").locale(Locale.GERMAN).date("2015-01-01").time("06:00:00").build();

        SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
        sdf.setCalendar(cal);
        String format = sdf.format(cal.getTime());

        assertEquals("Mo, 29 Dez 2014 06:00:00 +0100", format);
    }

}

@@ -1273,37 +1273,27 @@
 ().timzone(%22
-Europe/Berlin
+GMT
 %22).locale(Lo
@@ -1303,16 +1303,17 @@
 e.GERMAN
+Y
 ).build(
@@ -1365,29 +1365,19 @@
 Equals(%22
-Europe/Berlin
+GMT
 %22, cal.g
@@ -1505,37 +1505,27 @@
 ().timzone(%22
-Europe/Berlin
+GMT
 %22).locale(Lo
@@ -1527,32 +1527,33 @@
 le(Locale.GERMAN
+Y
 ).date(%222015-01-
@@ -1639,32 +1639,48 @@
 yyyy HH:mm:ss Z%22
+, Locale.GERMANY
 );%0A        sdf.s
@@ -1762,38 +1762,38 @@
   assertEquals(%22
-M
+S
 o, 2
-9
+8
  Dez 2014 00:00:
@@ -1786,18 +1786,18 @@
 ez 2014 
-00
+23
 :00:00 +
@@ -1789,33 +1789,33 @@
 2014 23:00:00 +0
-1
+0
 00%22, format);%0A  
@@ -1933,21 +1933,11 @@
 ne(%22
-Europe/Berlin
+GMT
 %22).l
@@ -1955,16 +1955,17 @@
 e.GERMAN
+Y
 ).date(%22
@@ -2084,16 +2084,32 @@
 mm:ss Z%22
+, Locale.GERMANY
 );%0A     
@@ -2224,17 +2224,17 @@
 z 2014 0
-6
+5
 :00:00 +
@@ -2234,17 +2234,17 @@
 00:00 +0
-1
+0
 00%22, for

Refactor Testcase