Skip to content

Commit

Permalink
Added unfolding test of binary attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Apr 10, 2018
1 parent 981fede commit a31c51d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/groovy/net/fortuna/ical4j/data/UnfoldingReaderSpec.groovy
@@ -0,0 +1,40 @@
package net.fortuna.ical4j.data

import net.fortuna.ical4j.model.Calendar
import net.fortuna.ical4j.model.ContentBuilder
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.property.Attach
import spock.lang.Specification

import java.security.MessageDigest

class UnfoldingReaderSpec extends Specification {

def 'verify unfolding encoded binary attachments'() {
given: 'a calendar object string with an encoded binary attachment'
def builder = new ContentBuilder()
def calendar = builder.calendar() {
prodid '-//Ben Fortuna//iCal4j 1.0//EN'
version '2.0'
vevent {
uid '1'
dtstamp()
dtstart '20090810', parameters: parameters { value 'DATE' }
action 'DISPLAY'
attach new Attach(new File('gradle/wrapper/gradle-wrapper.jar').bytes)
}
}

CalendarOutputter outputter = []
def calendarString = new StringWriter()
outputter.output(calendar, calendarString)

when: 'the calendar object string is parsed'
Calendar parsed = new CalendarBuilder().build(new StringReader(calendarString as String))

then: 'the encoded binary is decoded correctly'
def attach = parsed.components[0].getProperty(Property.ATTACH)
def md5 = MessageDigest.getInstance("MD5")
md5.digest(attach.binary) == md5.digest(new File('gradle/wrapper/gradle-wrapper.jar').bytes)
}
}

0 comments on commit a31c51d

Please sign in to comment.