/** * {@inheritDoc} */ @Override public PropertyPathStart getPropertyPathStart() { PropertyPathStart propertyPathStart = new PropertyPathStart(); propertyPathStart.setName(getDisplayName()); propertyPathStart.setContentType(ParameterContentType.RETURN); addPaths(propertyPathStart); return propertyPathStart; }
@Test public void nullNeededResultObjectForResultAccess() throws PropertyAccessException { PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.RETURN); String result = propertyAccessor.getPropertyContent(start, null, null, null, false); assertThat(result, is(equalTo("null"))); }
@Test public void analyzeReturnValueString() throws PropertyAccessException { // valid PropertyPathStart start = new PropertyPathStart(); start.setName("returnName"); start.setContentType(ParameterContentType.RETURN); String result = propertyAccessor.getPropertyContent(start, null, null, "Peter", false); assertThat(result, is("Peter")); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void nullNeededClassObjectForFieldAccess() throws PropertyAccessException { PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); propertyAccessor.getPropertyContent(start, null, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
/** * {@inheritDoc} */ @Override public PropertyPathStart getPropertyPathStart() { PropertyPathStart propertyPathStart = new PropertyPathStart(); propertyPathStart.setSignaturePosition(index); propertyPathStart.setName(getDisplayName()); propertyPathStart.setContentType(ParameterContentType.PARAM); addPaths(propertyPathStart); return propertyPathStart; }
@Test public void analyzeReturnValueVoidMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); // valid PropertyPathStart start = new PropertyPathStart(); start.setName("setName"); start.setContentType(ParameterContentType.RETURN); String result = propertyAccessor.getPropertyContent(start, null, null, peter, false); assertThat(result, is("Peter")); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void missingContentType() throws PropertyAccessException { PropertyPathStart start = new PropertyPathStart(); start.setName("name"); start.setSignaturePosition(0); propertyAccessor.getPropertyContent(start, null, null, null, false); }
@Test public void readFieldPersonObject() throws PropertyAccessException { Person person = new Person(); person.setName("Dirk"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); String result = propertyAccessor.getPropertyContent(start, person, null, resultValueMock, false); assertThat(result, is("Dirk")); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void nullNeededParameterObject() throws PropertyAccessException { PropertyPathStart start = new PropertyPathStart(); start.setName("name"); start.setSignaturePosition(0); start.setContentType(ParameterContentType.PARAM); propertyAccessor.getPropertyContent(start, null, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void parameterArrayOutOfRange() throws PropertyAccessException { PropertyPathStart start = new PropertyPathStart(); start.setName("name"); start.setSignaturePosition(0); start.setContentType(ParameterContentType.PARAM); propertyAccessor.getPropertyContent(start, null, new Object[0], resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
@Test public void analyzeReturnValueObjectException() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); Person juergen = new Person("Hans"); peter.setChild(juergen); List<PropertyPathStart> propertyAccessorList = new ArrayList<PropertyPathStart>(); // valid PropertyPathStart start = new PropertyPathStart(); start.setName("return"); start.setContentType(ParameterContentType.RETURN); PropertyPath pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); String result = propertyAccessor.getPropertyContent(start, null, null, peter, true); assertThat(result, is("n/a")); }
/** * {@inheritDoc} */ @Override public PropertyPathStart getPropertyPathStart() { PropertyPathStart propertyPathStart = new PropertyPathStart(); propertyPathStart.setName(getDisplayName()); propertyPathStart.setContentType(ParameterContentType.FIELD); // create field navigation PropertyPath fieldPath = new PropertyPath(); fieldPath.setName(fieldName); addPaths(fieldPath); // connect to the start and return propertyPathStart.setPathToContinue(fieldPath); return propertyPathStart; }
@Test public void analyzeReturnValueObject() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); Person juergen = new Person("Hans"); peter.setChild(juergen); List<PropertyPathStart> propertyAccessorList = new ArrayList<PropertyPathStart>(); // valid PropertyPathStart start = new PropertyPathStart(); start.setName("return"); start.setContentType(ParameterContentType.RETURN); PropertyPath pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); String result = propertyAccessor.getPropertyContent(start, null, null, peter, false); assertThat(result, is("Hans")); }
@Test public void readFieldPersonName() throws PropertyAccessException { Person person = new Person(); person.setName("Dirk"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("name"); start.setPathToContinue(path); String result = propertyAccessor.getPropertyContent(start, person, null, resultValueMock, false); assertThat(result, is("Dirk")); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void invokeForbiddenMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("getName()"); start.setPathToContinue(path); propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
@Test public void invokeListSizeMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); List<String> foreNames = new ArrayList<String>(); foreNames.add("blub"); foreNames.add("blub2"); foreNames.add("blub3"); peter.setForeNamesAsList(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("foreNamesAsList"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("size()"); path.setPathToContinue(path2); String result = propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); assertThat(Integer.parseInt(result), is(3)); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void analyzePersonAccessException() throws PropertyAccessException { Person person = new Person(); person.setName("Dirk"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("surname"); start.setPathToContinue(path); // name != surname -> exception propertyAccessor.getPropertyContent(start, person, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
@Test public void invokeArrayLengthMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); String[] foreNames = new String[] { "Klaus", "Uwe" }; peter.setForeNames(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("foreNames"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("length()"); path.setPathToContinue(path2); String result = propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); assertThat(Integer.parseInt(result), is(2)); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void invokeArrayLengthMethodOnNonArray() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); String[] foreNames = new String[] { "Klaus", "Uwe" }; peter.setForeNames(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("name"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("length()"); path.setPathToContinue(path2); // must result in an Exception as name is not an array propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
PropertyPathStart start = new PropertyPathStart(); start.setName("name"); start.setSignaturePosition(1);