Skip to content

Commit

Permalink
Minor FieldValueGeneratorFactory refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbak committed Sep 12, 2016
1 parent e84ff91 commit 66f697a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
* limitations under the License.
*/
public class FieldValueGeneratorFactory {
private static FieldValueGeneratorFactory factory = new FieldValueGeneratorFactory();
private FieldValueGeneratorFactory(){}

public static FieldValueGeneratorFactory instance(){
return factory;
}

public static FieldValueGenerator forCronField(CronField cronField){
FieldExpression fieldExpression = cronField.getExpression();
if(fieldExpression instanceof Always){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,22 @@
* limitations under the License.
*/
public class FieldValueGeneratorFactoryTest {
private FieldValueGeneratorFactory fieldValueGeneratorFactory;

private CronField mockCronField;
@Before
public void setUp() throws Exception {
fieldValueGeneratorFactory = FieldValueGeneratorFactory.instance();
mockCronField = mock(CronField.class);
}

@Test
public void testInstance() throws Exception {
assertNotNull(FieldValueGeneratorFactory.instance());
}

@Test
public void testForCronFieldAlways() throws Exception {
when(mockCronField.getExpression()).thenReturn(mock(Always.class));
assertEquals(AlwaysFieldValueGenerator.class, fieldValueGeneratorFactory.forCronField(mockCronField).getClass());
assertEquals(AlwaysFieldValueGenerator.class, FieldValueGeneratorFactory.forCronField(mockCronField).getClass());
}

@Test
public void testForCronFieldAnd() throws Exception {
when(mockCronField.getExpression()).thenReturn(mock(And.class));
assertEquals(AndFieldValueGenerator.class, fieldValueGeneratorFactory.forCronField(mockCronField).getClass());
assertEquals(AndFieldValueGenerator.class, FieldValueGeneratorFactory.forCronField(mockCronField).getClass());
}

@Test
Expand Down

0 comments on commit 66f697a

Please sign in to comment.