I'm trying to save on boilerplate code so tried to use { get; set; }
idiom, but the function will not resolve.
This is the class with decorated properties.
public class Counter {
private static Integer hits {get { if(hits == null) hits = 0; hits++; return hits; } private set; }
private static Boolean foo {get;set;}
}
My unit test, that will not build, I get the error: Method does not exist or incorrect signature: void getHits() from the type Counter on every assert line.
@isTest public class CounterTest extends AbstractTestCase {
@isTest static void testCounter() {
Test.startTest();
Counter count = new Counter();
assertNotNull(count);
// instance access, case sensitive and insensitive
System.assert(count.getHits() == 1);
System.assert(count.gethits() == 1);
// static access, case sensitive and insensitive
System.assert(Counter.getHits() == 2);
System.assert(Counter.gethits() == 2);
// even trivial example doesn't work
count.setFoo(true);
System.assert(getFoo());
// I even tried direct access,
System.debug('count : ' + Counter.hits);
System.assert(Counter.hits == 1);
Test.stopTest();
}
}
I've using v44 of apex, how on earth are these used?
Yes, there are lot of questions about { get; set; }
but non address this specific point