In the jUnit test, I want to get some rows from a database based on the name column. Then I want to check that the lines that I have have the names that I expected. I have the following:
Set<MyClass> typesToGet = MyClassFactory.createInstances("furniture", "audio equipment"); Collection<String> namesToGet = Collections2.transform(typesToGet, new NameFunction<MyClass, String>()); List<MyClass> typesGotten = _svc.getAllByName(typesToGet); assertThat(typesGotten.size(), is(typesToGet.size())); Collection<String> namesGotten = Collections2.transform(typesGotten, new NameFunction<ItemType, String>()); assertEquals(namesToGet, namesGotten);
I am currently receiving this failure:
java.lang.AssertionError: expected: com.google.common.collect.Collections2 $ TransformedCollection <[audio equipment, furniture]> but it was: com.google.common.collect.Collections2 $ TransformedCollection <[audio equipment, furniture]>
So, what is the cleanest, shortest way to verify that I got rows from the database, the name column matches the names that I said I wanted? I could loop through the for loop and verify that each name in one list exists in another, but I was hoping to be more concise. Something like the following pseudo code would be nice:
List<MyClass> typesGotten = ...; ["furniture", "audio equipment"].equals(typesGotten.map(type => type.getName()))
Sarah vessels
source share