how scathing category final methods?


say i have category with



class {
final twine foo() {
// .. computing result, contacting database, whatever ..
relapse "some computed value";
}
// ... bazillion methods, final.
}


now i have category b with



class b {
twine methodiwanttotest(a a) {
twine cost = a.foo();
// ... whatever slight does, e.g.:
cost += "_suffix";
relapse output;
}
}


how i section contrast method? reason foo() final since don't wish the classes extend change the functionality. nonetheless during same truly section exam method, i don't wish strech out run tangible a.foo() method.



is there proceed to, say, mislay final keyword supplement an comment along lines @finalunlesstest? recommend? refactoring an interface very, unequivocally difficult, observant it's the executive classes unfortunately pretty severely coupled.



edit #1 sorry, forgot mention, we're articulate java. controlling scathing horizon yet.



answer ok, so: wow. only improbable eyes torpedo app contrast leave code. unbelievably useful generally case. interjection much! fundamentally something following psuedo-example:



class amock {
final twine foo() {
relapse "mytestvalue";
}
}
class exam extends testcase {
mockeda;
b b;
stable vacant setup() {
mockit.redefinemethods( a.class, amock.class ); // "pipes" mocked methods amock
mockeda = new a(); // new amock()!!!
b = new b();
}
open vacant testb() {
assertequals("mytestvalue",mockeda.foo());
assertequals("mytestvalue_suffix",b.methodiwanttotest(mockeda));
}
}


is frickin' cold what?



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members