Skip to content

Commit

Permalink
Improve class coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jun 12, 2018
1 parent b3aa0a8 commit 16720cc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
@@ -0,0 +1,40 @@
package net.fortuna.ical4j.util

import net.fortuna.ical4j.model.parameter.Encoding
import org.apache.commons.codec.BinaryEncoder
import org.apache.commons.codec.StringEncoder
import spock.lang.Specification

class DefaultEncoderFactoryTest extends Specification {

DefaultEncoderFactory factory = []

def "CreateBinaryEncoder"() {
expect: 'a binary encoder'
def encoder = factory.createBinaryEncoder(encoding)
encoder instanceof BinaryEncoder

where:
encoding << [Encoding.BASE64, Encoding.QUOTED_PRINTABLE]
}

def "CreateStringEncoder"() {
expect: 'a string encoder'
def encoder = factory.createStringEncoder(encoding)
encoder instanceof StringEncoder

where:
encoding << [Encoding.QUOTED_PRINTABLE]
}

def "assert invalid encoding"() {
given: 'an invalid string encoding'
def encoding = Encoding.BASE64

when: 'attempt to create encoder'
factory.createStringEncoder(encoding)

then: 'invalid encoding exception'
thrown(UnsupportedEncodingException)
}
}
@@ -1,5 +1,6 @@
package net.fortuna.ical4j.util

import net.fortuna.ical4j.model.DateTime
import spock.lang.Specification

class FixedUidGeneratorSpec extends Specification {
Expand All @@ -15,4 +16,16 @@ class FixedUidGeneratorSpec extends Specification {
then: 'HostInfo.getHostName() is only called once'
1 * hostInfo.getHostName()
}

def "verify generated uid"() {
given: 'a simple host info'
def hostInfo = new SimpleHostInfo('test')

when: 'a generator is created and a uid is generated multiple times'
FixedUidGenerator generator = [hostInfo, '1']
def uid = generator.generateUid()

then: 'uid is as expected'
uid.value == (new DateTime(utc: true) as String) + '-1@' + hostInfo.hostName
}
}

0 comments on commit 16720cc

Please sign in to comment.