Skip to content

Commit 5f9802c

Browse files
authored
Fix availability mapping for events (don't write NULL values) (#133)
* Fix availability mapping for events (don't write NULL values) * Fix tests
1 parent e48bdbd commit 5f9802c

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

lib/src/main/kotlin/at/bitfire/synctools/mapping/calendar/builder/AvailabilityBuilder.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ class AvailabilityBuilder: AndroidEntityBuilder {
1515

1616
override fun build(from: VEvent, main: VEvent, to: Entity) {
1717
val availability = when (from.transparency) {
18-
Transp.OPAQUE ->
19-
Events.AVAILABILITY_BUSY
20-
2118
Transp.TRANSPARENT ->
2219
Events.AVAILABILITY_FREE
2320

24-
// Default value in iCalendar is OPAQUE, but we set it to null to indicate that it was not set in the iCalendar.
25-
else ->
26-
null
21+
// Default value in iCalendar is OPAQUE
22+
else /* including Transp.OPAQUE */ ->
23+
Events.AVAILABILITY_BUSY
2724
}
2825
to.entityValues.put(
2926
Events.AVAILABILITY,

lib/src/main/kotlin/at/bitfire/synctools/mapping/calendar/processor/AvailabilityProcessor.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@ import net.fortuna.ical4j.model.property.Transp
1414
class AvailabilityProcessor: AndroidEventFieldProcessor {
1515

1616
override fun process(from: Entity, main: Entity, to: VEvent) {
17-
val transp = when (from.entityValues.getAsInteger(Events.AVAILABILITY)) {
18-
Events.AVAILABILITY_BUSY,
19-
Events.AVAILABILITY_TENTATIVE ->
20-
Transp.OPAQUE
21-
17+
val transp: Transp = when (from.entityValues.getAsInteger(Events.AVAILABILITY)) {
2218
Events.AVAILABILITY_FREE ->
2319
Transp.TRANSPARENT
2420

21+
/* Events.AVAILABILITY_BUSY, Events.AVAILABILITY_TENTATIVE */
2522
else ->
26-
null // defaults to OPAQUE in iCalendar
23+
Transp.OPAQUE
2724
}
28-
if (transp != null)
25+
if (transp != Transp.OPAQUE) // iCalendar default value is OPAQUE
2926
to.properties += transp
3027
}
3128

lib/src/test/kotlin/at/bitfire/synctools/mapping/calendar/builder/AvailabilityBuilderTest.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ package at.bitfire.synctools.mapping.calendar.builder
99
import android.content.ContentValues
1010
import android.content.Entity
1111
import android.provider.CalendarContract.Events
12-
import androidx.core.content.contentValuesOf
1312
import at.bitfire.synctools.icalendar.propertyListOf
14-
import at.bitfire.synctools.test.assertContentValuesEqual
1513
import net.fortuna.ical4j.model.component.VEvent
1614
import net.fortuna.ical4j.model.property.Transp
17-
import org.junit.Assert.assertNull
15+
import org.junit.Assert.assertEquals
1816
import org.junit.Assert.assertTrue
1917
import org.junit.Test
2018
import org.junit.runner.RunWith
@@ -34,7 +32,7 @@ class AvailabilityBuilderTest {
3432
to = result
3533
)
3634
assertTrue(result.entityValues.containsKey(Events.AVAILABILITY))
37-
assertNull(result.entityValues.get(Events.AVAILABILITY))
35+
assertEquals(Events.AVAILABILITY_BUSY, result.entityValues.get(Events.AVAILABILITY))
3836
}
3937

4038
@Test
@@ -45,9 +43,7 @@ class AvailabilityBuilderTest {
4543
main = VEvent(),
4644
to = result
4745
)
48-
assertContentValuesEqual(contentValuesOf(
49-
Events.AVAILABILITY to Events.AVAILABILITY_BUSY
50-
), result.entityValues)
46+
assertEquals(Events.AVAILABILITY_BUSY, result.entityValues.get(Events.AVAILABILITY))
5147
}
5248

5349
@Test
@@ -58,9 +54,7 @@ class AvailabilityBuilderTest {
5854
main = VEvent(),
5955
to = result
6056
)
61-
assertContentValuesEqual(contentValuesOf(
62-
Events.AVAILABILITY to Events.AVAILABILITY_FREE
63-
), result.entityValues)
57+
assertEquals(Events.AVAILABILITY_FREE, result.entityValues.get(Events.AVAILABILITY))
6458
}
6559

6660
}

lib/src/test/kotlin/at/bitfire/synctools/mapping/calendar/processor/AvailabilityProcessorTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AvailabilityProcessorTest {
2929
val result = VEvent()
3030
val entity = Entity(ContentValues())
3131
processor.process(entity, entity, result)
32+
// OPAQUE is default value
3233
assertNull(result.getProperty<Transp>(Property.TRANSP))
3334
}
3435

@@ -39,7 +40,8 @@ class AvailabilityProcessorTest {
3940
Events.AVAILABILITY to Events.AVAILABILITY_BUSY
4041
))
4142
processor.process(entity, entity, result)
42-
assertEquals(Transp.OPAQUE, result.getProperty<Transp>(Property.TRANSP))
43+
// OPAQUE is default value
44+
assertNull(result.getProperty<Transp>(Property.TRANSP))
4345
}
4446

4547
@Test
@@ -59,7 +61,8 @@ class AvailabilityProcessorTest {
5961
Events.AVAILABILITY to Events.AVAILABILITY_TENTATIVE
6062
))
6163
processor.process(entity, entity, result)
62-
assertEquals(Transp.OPAQUE, result.getProperty<Transp>(Property.TRANSP))
64+
// OPAQUE is default value
65+
assertNull(result.getProperty<Transp>(Property.TRANSP))
6366
}
6467

6568
}

0 commit comments

Comments
 (0)