Object result = null;
// 1
FakeAbstractConfiguration conf = new FakeAbstractConfiguration();
entryName = conf.validEntryName;
defaultValue = new DefaultTestComponent();
data = new Object();
result = callGetEntry(conf,
testCase,
componentName,
entryName,
TestComponent.class,
defaultValue,
data);
if (!(conf.getComponent().equals(componentName))) {
throw new TestException(
"component argument was not delivered successfully");
}
if (!(conf.getName().equals(entryName))) {
throw new TestException(
"name argument was not delivered successfully");
}
if (!(conf.getType().equals(TestComponent.class))) {
throw new TestException(
"type argument was not delivered successfully");
}
if (testCase == GET_ENTRY_5ARG_CASE
&& !(conf.getData().equals(data))) {
throw new TestException(
"data argument was not delivered successfully");
}
if (conf.getReturn() != result) {
throw new TestException(
"getEntry returns invalid object");
}
// 2
if ( testCase == GET_ENTRY_4ARG_CASE
|| testCase == GET_ENTRY_5ARG_CASE) {
conf = new FakeAbstractConfiguration();
entryName = "unexistEntry";
defaultValue = new DefaultTestComponent();
result = callGetEntry(conf,
testCase,
componentName,
entryName,
TestComponent.class,
defaultValue,
data);
if (!(result.equals(defaultValue))) {
throw new TestException(
"getEntry should return default test component");
}
}
// 3
if ( testCase == GET_ENTRY_4ARG_CASE
|| testCase == GET_ENTRY_5ARG_CASE) {
conf = new FakeAbstractConfiguration();
entryName = "unexistEntry";
try {
result = callGetEntry(conf,
testCase,
componentName,
entryName,
TestComponent.class,
Configuration.NO_DEFAULT,
data);
throw new TestException(
"NoSuchEntryException should be thrown"
+ " in case of absent entry"
+ " and dafault value is equal to"
+ " Configuration.NO_DEFAULT");
} catch (NoSuchEntryException ignore) {
logger.log(Level.INFO,
"NoSuchEntryException in case of absent entry"
+ " and dafault value is equal to"
+ " Configuration.NO_DEFAULT");
}
}
// 4
for (int j = 0; j < primitiveCases.length; ++j) {
Object[] subCase = primitiveCases[j];
logger.log(Level.INFO, "-- subcase: " + subCase[0]);
entryName = (String) subCase[0];
Object returnValue = subCase[1];
defaultValue = subCase[2];
Class entryType = (Class) subCase[3];
conf = new FakeAbstractConfiguration();
result = callGetEntry(conf, testCase, componentName,
entryName, entryType, defaultValue, null);
if (!(result.equals(returnValue))) {
throw new TestException(
"getEntry returns invalid value: " + result);
}
}
// 5
conf = new FakeAbstractConfiguration();
entryName = conf.validEntryName;
try {
result = callGetEntry(conf,
testCase,
null,
entryName,
TestComponent.class,
Configuration.NO_DEFAULT,
null);
throw new TestException(
"NullPointerException should be thrown if"
+ " component is null");
} catch (NullPointerException ignore) {
logger.log(Level.INFO,
"NullPointerException in case of"
+ " component is null");
}
// 6
conf = new FakeAbstractConfiguration();
try {
result = callGetEntry(conf,
testCase,
componentName,
null,
TestComponent.class,
Configuration.NO_DEFAULT,
null);
throw new TestException(
"NullPointerException should be thrown if"
+ " name is null");
} catch (NullPointerException ignore) {
logger.log(Level.INFO,
"NullPointerException in case of"
+ " name is null");
}
// 7
conf = new FakeAbstractConfiguration();
entryName = conf.validEntryName;
try {
result = callGetEntry(conf,
testCase,
componentName,
entryName,
null,
Configuration.NO_DEFAULT,
null);
throw new TestException(
"NullPointerException should be thrown if"
+ " type is null");
} catch (NullPointerException ignore) {
logger.log(Level.INFO,
"NullPointerException in case of"
+ " type is null");
}
// 8
conf = new FakeAbstractConfiguration();
entryName = conf.validEntryName;
try {
result = callGetEntry(conf,
testCase,
"invalid qualified identifier",
entryName,
TestComponent.class,
Configuration.NO_DEFAULT,
null);
throw new TestException(
"IllegalArgumentException should be thrown if"
+ " component is not valid qualified identifier");
} catch (IllegalArgumentException ignore) {
logger.log(Level.INFO,
"IllegalArgumentException in case of"
+ " component is not valid qualified identifier");
}
// 9
conf = new FakeAbstractConfiguration();
entryName = conf.validEntryName;
try {
result = callGetEntry(conf,
testCase,
componentName,
"invalid identifier",
TestComponent.class,
Configuration.NO_DEFAULT,
null);
throw new TestException(
"IllegalArgumentException should be thrown if"
+ " name is not valid identifier");
} catch (IllegalArgumentException ignore) {
logger.log(Level.INFO,
"IllegalArgumentException in case of"
+ " name is not valid identifier");
}
// 10
if ( testCase == GET_ENTRY_4ARG_CASE
|| testCase == GET_ENTRY_5ARG_CASE) {
conf = new FakeAbstractConfiguration();
entryName = conf.validEntryName;
try {
result = callGetEntry(conf,
testCase,
componentName,
entryName,
TestComponent.class,
new Object(),
null);
throw new TestException(
"IllegalArgumentException should be thrown if"
+ " defaultValue is not of the right type");
} catch (IllegalArgumentException ignore) {
logger.log(Level.INFO,
"IllegalArgumentException in case of"
+ " defaultValue is not of the right type");
}
}
// 11
final Throwable[] exceptionList = {
new java.lang.ArrayIndexOutOfBoundsException(),
new java.lang.SecurityException(),
new java.lang.NullPointerException(),
new java.lang.ArithmeticException(),
new java.lang.ArrayStoreException(),
new java.lang.ClassCastException(),
new java.util.EmptyStackException(),
new java.lang.IllegalArgumentException(),
new java.lang.IllegalMonitorStateException(),
new java.lang.IllegalStateException(),
new java.lang.IndexOutOfBoundsException(),
new java.util.MissingResourceException("","",""),
new java.lang.NegativeArraySizeException(),
new java.util.NoSuchElementException(),
new java.lang.NullPointerException(),
new java.security.ProviderException(),
new java.lang.SecurityException(),
new java.lang.reflect.UndeclaredThrowableException(null),
new java.lang.UnsupportedOperationException() };
for (int e = 0; e < exceptionList.length; ++e) {
Throwable testException = exceptionList[e];
logger.log(Level.INFO, "-- subcase: " + testException);
conf = new FakeAbstractConfiguration();
conf.setException(testException);
entryName = conf.validEntryName;
defaultValue = new DefaultTestComponent();
data = new Object();
try {
result = callGetEntry(conf, testCase, componentName, entryName,
TestComponent.class, defaultValue, data);
throw new TestException(
"getEntry should throw an exception");
} catch (ConfigurationException ce) {
if (!(ce.getCause().equals(testException))) {
throw new TestException(
"getEntry throws an exception with invalid cause");
}
}
}
conf.setException(null);
// 12
final Throwable[] exceptionList2 = {
new ConfigurationException(""),
new ConfigurationNotFoundException(""),
new NoSuchEntryException(""),
new Error() };
for (int e = 0; e < exceptionList2.length; ++e) {
Throwable testException = exceptionList2[e];
logger.log(Level.INFO, "-- subcase: " + testException);
conf = new FakeAbstractConfiguration();
conf.setException(testException);
entryName = conf.validEntryName;
defaultValue = Configuration.NO_DEFAULT;
data = new Object();
try {
result = callGetEntry(conf, testCase, componentName, entryName,
TestComponent.class, defaultValue, data);
throw new TestException(
"getEntry should throw an exception");
} catch (ConfigurationException ce) {
if (!(ce.equals(testException))) {
throw new TestException(
"getEntry throws invalid exception");
}
} catch (Error er) {
if (!(er.equals(testException))) {
throw new TestException(
"getEntry throws an exception with invalid cause");
}
}
}
conf.setException(null);
// 13
conf = new FakeAbstractConfiguration();
conf.setReturn(new Object());
entryName = conf.validEntryName;
defaultValue = new DefaultTestComponent();
data = new Object();
try {
result = callGetEntry(conf,
testCase,
componentName,