merrimanr commented on a change in pull request #1399: METRON-2073: Create in-memory use case for enrichment with map type and flatfile summarizer URL: https://github.com/apache/metron/pull/1399#discussion_r286697377
########## File path: metron-platform/metron-enrichment/metron-enrichment-common/src/test/java/org/apache/metron/enrichment/stellar/ObjectGetTest.java ########## @@ -18,73 +18,88 @@ package org.apache.metron.enrichment.stellar; -import com.google.common.collect.ImmutableMap; -import org.apache.commons.io.IOUtils; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.metron.common.utils.SerDeUtils; -import org.apache.metron.stellar.common.utils.StellarProcessorUtils; -import org.junit.Assert; +import org.apache.metron.enrichment.cache.ObjectCache; +import org.apache.metron.enrichment.cache.ObjectCacheConfig; +import org.apache.metron.stellar.dsl.Context; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; -import java.io.BufferedOutputStream; -import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; -import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ObjectGet.class, ObjectCache.class}) public class ObjectGetTest { - FileSystem fs; - List<String> data; + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private ObjectGet objectGet; + private ObjectCache objectCache; + private Context context; @Before - public void setup() throws IOException { - fs = FileSystem.get(new Configuration()); - data = new ArrayList<>(); - { - data.add("apache"); - data.add("metron"); - data.add("is"); - data.add("great"); - } + public void setup() throws Exception { + objectGet = new ObjectGet(); + objectCache = mock(ObjectCache.class); Review comment: You make some good points on the tradeoffs of using mocks vs using real classes. In this case though, I don't agree that using the real ObjectCache class would be simpler. Using a mock object for the cache is pretty simple here. The mock is set up to return values from method calls and verify methods were called correctly. This is done with only a couple lines of code. If we were to use the real ObjectCache, now we have to: - Create an arbitrary cache configuration - Create a test Loader and inject it instead of the default Loader - Setup and instantiate the cache This is more complex in my opinion. Plus any change to the ObjectCache setup requirements would also require an update to this test. I've experienced pain in the past where a change to a low level class required significant changes to several different tests because the tests were relying on the real implementation rather than being isolated to the class it's testing. Again, I take your point that we should be cautious about over-using mocks. But I don't think it applies here. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services