java - converter class test driven -


i have class, should convert data 1 format (database librarytype). looks like:

public librarytype converttolibrary(database db, parameters params) {      preconditions.checknotnull(db," missing database conversion");     preconditions.checknotnull(params, "missing parameters conversion");      librarytype lib = basicfactory.createlibrarytype();     lib.setname(db.getname());     componenttype type = convertstructure(db.getstructure(),params);      if (type != componenttype.empty) {         lib.addcomponent(type);     }      return lib; }  componenttype convertstructure(structure s, parameters params) {     if (!params.isstructureallowed(s)) return componenttype.empty;     componenttype comp = basicfactory.createcomponenttype();           comp.setname(s.getname());    return comp; } 

i have 2 problems concept.

  1. the method convertstructure should private, because not neccessary call outside, testing purposes defined package-wide, not nice

  2. the parameters (params) passed sub-method. use class field insert during constructor, because of using guice di-framework, cannot pass data constructor. parameters change during runtime. need pass method parameter. set class field in converttolibrary method, cannot test method convertstructure.

did run design problem or there useful workarounds? make sense split different classes, not sound me, because still feel 1 responsibility (srp) in class (converting data)?

thanks help

answer question 1 (and perhaps question 2):

if feel need write test convertstructure(), think sign should in own class. test should not test things smaller single responsibility (imo).

that said, i'm not sure need test convertstructure() in isolation. isn't testing convertlibrary() enough? or perhaps larger unit?

opinion: have preference of testing outside in, testing @ high level start , testing smaller parts when need to. start testing behaviour, seen user of system, , test implementation details when needed. not agrees me though.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -