mardi 30 juillet 2019

Testing with AssertJ if two lists are equal (without order)

I want to test if 2 given lists are equal. They should have the same elements, but the order is no matter. I am trying to do this with assertj and the method containsExactlyInAnyOrder(). The test throws an error and shows me what is expected and what is found and i dont see any difference between them. Can you guys explain me the problem here?

@Test
    void test_getAllCalendarEntriesAsList_shouldBeEqualToCreatedFiles() {
        final List<ICalendar> iCalendarList = new ArrayList<>();
        for (int i = 0; i < 1; i++) {
            final ICalendar sampleICalendar = this.createSampleICalendar();
            iCalendarList.add(sampleICalendar);
        }
        storageManager.saveEntries(iCalendarList);

        final List<ICalendar> allCalendarEntriesAsList = storageManager.getAllCalendarEntriesAsList();
        final ICalendar[] iCalendars = iCalendarList.toArray(new ICalendar[allCalendarEntriesAsList.size()]);
        assertThat(allCalendarEntriesAsList).containsExactlyInAnyOrder(iCalendars);
    }

Message:

java.lang.AssertionError: 
Expecting:
  <[biweekly.ICalendar {version=2.0}
  biweekly.property.ProductId [ parameters={} | value=-//Michael Angstadt//biweekly 0.6.3//EN ]
  biweekly.property.Name [ parameters={} | value=Test name ]
  biweekly.component.VEvent
    biweekly.property.Uid [ parameters={} | value=067463ea-9a36-46d8-bbab-460c550cfd18 ]
    biweekly.property.DateTimeStamp [ parameters={} | value=Wed Jul 31 06:59:00 CEST 2019 ]
    biweekly.property.Summary [ parameters={LANGUAGE=[en-us]} | value=Meeting with Team A ]
    biweekly.property.DateStart [ parameters={} | value=Wed Jul 31 00:00:00 CEST 2019 ]
    biweekly.property.DurationProperty [ parameters={} | value=PT1H ]
]>
to contain exactly in any order:
  <[biweekly.ICalendar {version=2.0}
  biweekly.property.ProductId [ parameters={} | value=-//Michael Angstadt//biweekly 0.6.3//EN ]
  biweekly.property.Name [ parameters={} | value=Test name ]
  biweekly.component.VEvent
    biweekly.property.Uid [ parameters={} | value=067463ea-9a36-46d8-bbab-460c550cfd18 ]
    biweekly.property.DateTimeStamp [ parameters={} | value=Wed Jul 31 06:59:00 CEST 2019 ]
    biweekly.property.Summary [ parameters={LANGUAGE=[en-us]} | value=Meeting with Team A ]
    biweekly.property.DateStart [ parameters={} | value=Wed Jul 31 00:00:00 CEST 2019 ]
    biweekly.property.DurationProperty [ parameters={} | value=PT1H ]
]>
elements not found:
  <[biweekly.ICalendar {version=2.0}
  biweekly.property.ProductId [ parameters={} | value=-//Michael Angstadt//biweekly 0.6.3//EN ]
  biweekly.property.Name [ parameters={} | value=Test name ]
  biweekly.component.VEvent
    biweekly.property.Uid [ parameters={} | value=067463ea-9a36-46d8-bbab-460c550cfd18 ]
    biweekly.property.DateTimeStamp [ parameters={} | value=Wed Jul 31 06:59:00 CEST 2019 ]
    biweekly.property.Summary [ parameters={LANGUAGE=[en-us]} | value=Meeting with Team A ]
    biweekly.property.DateStart [ parameters={} | value=Wed Jul 31 00:00:00 CEST 2019 ]
    biweekly.property.DurationProperty [ parameters={} | value=PT1H ]
]>
and elements not expected:
  <[biweekly.ICalendar {version=2.0}
  biweekly.property.ProductId [ parameters={} | value=-//Michael Angstadt//biweekly 0.6.3//EN ]
  biweekly.property.Name [ parameters={} | value=Test name ]
  biweekly.component.VEvent
    biweekly.property.Uid [ parameters={} | value=067463ea-9a36-46d8-bbab-460c550cfd18 ]
    biweekly.property.DateTimeStamp [ parameters={} | value=Wed Jul 31 06:59:00 CEST 2019 ]
    biweekly.property.Summary [ parameters={LANGUAGE=[en-us]} | value=Meeting with Team A ]
    biweekly.property.DateStart [ parameters={} | value=Wed Jul 31 00:00:00 CEST 2019 ]
    biweekly.property.DurationProperty [ parameters={} | value=PT1H ]
]>


    at de.htw.ai.decentralised_calendar.storage.ICalendarStorageManagerTest.test_getAllCalendarEntriesAsList_shouldBeEqualToCreatedFiles(ICalendarStorageManagerTest.java:180)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:532)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:171)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:167)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:108)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Aucun commentaire:

Enregistrer un commentaire