Skip to content

Commit

Permalink
joelittlejohn#113 Add RuleLogger mocking to some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddcruver committed Nov 5, 2019
1 parent 8365804 commit 71c4632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.Mockito.*;

import org.jsonschema2pojo.Annotator;
import org.jsonschema2pojo.RuleLogger;
import org.jsonschema2pojo.Schema;
import org.jsonschema2pojo.util.NameHelper;
import org.junit.Before;
Expand All @@ -44,12 +45,14 @@ public class EnumRuleTest {
private Annotator annotator = mock(Annotator.class);
private RuleFactory ruleFactory = mock(RuleFactory.class);
private TypeRule typeRule = mock(TypeRule.class);
private RuleLogger logger = mock(RuleLogger.class);

private EnumRule rule = new EnumRule(ruleFactory);

@Before
public void wireUpConfig() {
when(ruleFactory.getNameHelper()).thenReturn(nameHelper);
when(ruleFactory.getLogger()).thenReturn(logger);
when(ruleFactory.getAnnotator()).thenReturn(annotator);
when(ruleFactory.getTypeRule()).thenReturn(typeRule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.jsonschema2pojo.RuleLogger;
import org.junit.Test;

import org.jsonschema2pojo.DefaultGenerationConfig;
Expand Down Expand Up @@ -76,11 +77,25 @@ public void factoryMethodsCreateRules() {
public void generationConfigIsReturned() {

GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
RuleLogger mockRuleLogger = mock(RuleLogger.class);

RuleFactory ruleFactory = new RuleFactory(mockGenerationConfig, new NoopAnnotator(), new SchemaStore());
ruleFactory.setLogger(mockRuleLogger);

assertThat(ruleFactory.getGenerationConfig(), is(sameInstance(mockGenerationConfig)));
assertThat(ruleFactory.getLogger(), is(sameInstance(mockRuleLogger)));
}

@Test
public void generationRuleLoggerIsReturned() {

GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
RuleLogger mockRuleLogger = mock(RuleLogger.class);

RuleFactory ruleFactory = new RuleFactory(new DefaultGenerationConfig(), new NoopAnnotator(), new SchemaStore());
ruleFactory.setLogger(mockRuleLogger);

assertThat(ruleFactory.getLogger(), is(sameInstance(mockRuleLogger)));
}

@Test
Expand All @@ -91,7 +106,5 @@ public void schemaStoreIsReturned() {
RuleFactory ruleFactory = new RuleFactory(new DefaultGenerationConfig(), new NoopAnnotator(), mockSchemaStore);

assertThat(ruleFactory.getSchemaStore(), is(sameInstance(mockSchemaStore)));

}

}

0 comments on commit 71c4632

Please sign in to comment.