/** * Ensures that after de-serialization a calendar can still be copied. */ public void testShouldSerializeDeserializeCorrectly() throws IOException, ClassNotFoundException, ParseException, URISyntaxException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(this.calendar); oos.flush(); assertNotNull(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); Calendar copy = (Calendar) ois.readObject(); assertNotNull(copy); assertEquals(copy, this.calendar); Calendar newCopy = new Calendar(copy); assertEquals(newCopy, copy); }
/** * */ public void testGetContentType() { assertEquals(expectedContentType, Calendars.getContentType(calendar, charset)); }
/** * Test loading of calendars. * * @throws IOException * @throws ParserException */ public void testLoadFileNotFoundException() throws IOException, ParserException { try { Calendars.load(path); fail("Should throw FileNotFoundException"); } catch (NoSuchFileException fnfe) { LOG.info("Caught exception: " + fnfe.getMessage()); } }
/** * Test loading of calendars. * * @throws IOException * @throws ParserException */ public void testLoad() throws IOException, ParserException { assertNotNull(Calendars.load(resource)); }
TestSuite suite = new TestSuite(); suite.addTest(new CalendarsTest("testLoad", "/samples/valid/Australian32Holidays.ics")); suite.addTest(new CalendarsTest("testLoadFileNotFoundException", "/samples/valid/doesnt-exist.ics")); suite.addTest(new CalendarsTest("testLoadParserException", "/samples/invalid/google_aus_holidays.ics")); suite.addTest(new CalendarsTest("testMerge", (Calendar[]) calendars.toArray(new Calendar[calendars.size()]))); suite.addTest(new CalendarsTest("testSplit", calendar, 10)); suite.addTest(new CalendarsTest("testGetContentType", calendar, null, "text/calendar")); suite.addTest(new CalendarsTest("testGetContentType", calendar, null, "text/calendar; method=PUBLISH")); suite.addTest(new CalendarsTest("testGetContentType", calendar, Charset.forName("US-ASCII"), "text/calendar; method=PUBLISH; charset=US-ASCII")); suite.addTest(new CalendarsTest("testShouldSerializeDeserializeCorrectly", Calendars.load(CalendarsTest.class.getResource("/samples/valid/Australian32Holidays.ics")), -1));
/** * Test merging of calendars. */ public void testMerge() throws IOException, ParserException { Calendar result = calendars[0]; for (int i = 1; i < calendars.length; i++) { result = Calendars.merge(result, calendars[i]); } for (int i = 0; i < calendars.length; i++) { for (Property p : calendars[i].getProperties()) { assertTrue("Property [" + p + "] not found in merged calendar", result.getProperties().contains(p)); } for (Component c : calendars[i].getComponents()) { assertTrue("Component [" + c + "] not found in merged calendar", result.getComponents().contains(c)); } } }
/** * Test calendar split. */ public void testSplit() throws IOException, ParserException { Calendar[] split = Calendars.split(calendar); assertEquals(expectedCount, split.length); }
/** * Test loading of calendars. * * @throws IOException */ public void testLoadParserException() throws IOException { try { Calendars.load(resource); fail("Should throw ParserException"); } catch (ParserException pe) { LOG.info("Caught exception: " + pe.getMessage()); } }