DefaultSejdaContext implements SejdaContext { @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Task<? extends TaskParameters> getTask(TaskParameters parameters) throws TaskException { Class<? extends TaskParameters> parametersClass = parameters.getClass(); Class<? extends Task> taskClass = GlobalConfiguration.getInstance().getTasksRegistry().getTask(parametersClass); if (taskClass == null) { throw new TaskNotFoundException( String.format("Unable to find a Task class able to execute %s", parametersClass)); } try { Constructor<? extends Task> constructor = taskClass.getConstructor(); return constructor.newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) { throw new TaskException(ERROR_INSTANTIATING_THE_TASK, e); } catch (NoSuchMethodException e) { throw new TaskException(String.format("The task %s doesn't define a public no-args contructor.", taskClass), e); } }  @Override final Class<? extends NotificationStrategy> getNotificationStrategy(); @Override boolean isValidation(); boolean isIgnoreXmlConfiguration(); @Override @SuppressWarnings({ "rawtypes", "unchecked" }) Task<? extends TaskParameters> getTask(TaskParameters parameters);  }
@Test public void testGetTaskPositive() throws TaskException { Task<? extends TaskParameters> task = victim.getTask(new TestTaskParameter()); Assert.assertNotNull(task); }
@Test public void testGetTaskPositiveNearest() throws TaskException { Task<? extends TaskParameters> task = victim.getTask(new ChildTestTaskParameter()); Assert.assertNotNull(task); }
@Test(expected = TaskNotFoundException.class) public void testGetTaskNegative() throws TaskException { Task<? extends TaskParameters> task = victim.getTask(mock(TaskParameters.class)); Assert.assertNotNull(task); }