@Test
public void parseEmbedded() throws Exception {

    // parse just dates
    DateTime dt0 = DateTimeUtil.parseEmbedded("app-2009-06-24.log.gz", "yyyy-MM-dd", DateTimeZone.UTC);
    logger.debug("dt = " + dt0);
    Assert.assertEquals(new DateTime(2009,6,24,0,0,0,0,DateTimeZone.UTC), dt0);
    // parse a date and time
    dt0 = DateTimeUtil.parseEmbedded("app-2009-06-24-051112.log.gz", "yyyy-MM-dd-hhmmss", DateTimeZone.UTC);
    logger.debug("dt = " + dt0);
    Assert.assertEquals(new DateTime(2009,6,24,5,11,12,0,DateTimeZone.UTC), dt0);
    // parse different date format
    dt0 = DateTimeUtil.parseEmbedded("app-20090624-051112.log.gz", "yyyyMMdd-hhmmss", DateTimeZone.UTC);
    logger.debug("dt = " + dt0);
    Assert.assertEquals(new DateTime(2009,6,24,5,11,12,0,DateTimeZone.UTC), dt0);
    // parse just year and month
    dt0 = DateTimeUtil.parseEmbedded("app-200906.log.gz", "yyyyMM", DateTimeZone.UTC);
    logger.debug("dt = " + dt0);
    Assert.assertEquals(new DateTime(2009,6,1,0,0,0,0,DateTimeZone.UTC), dt0);
    try {
        // filename is missing a day
        dt0 = DateTimeUtil.parseEmbedded("app-200906.log.gz", "yyyyMMdd", DateTimeZone.UTC);
        Assert.fail("parse should have failed");
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
    try {
        // june only has 30 days
        dt0 = DateTimeUtil.parseEmbedded("app-20090631.log.gz", "yyyyMMdd", DateTimeZone.UTC);
        Assert.fail("parse should have failed");
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
    try {
        // tt isn't a valid pattern
        dt0 = DateTimeUtil.parseEmbedded("app-20090631.log.gz", "yyyyMMtt", DateTimeZone.UTC);
        Assert.fail("parse should have failed");
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
}