### Question:
SearchModel { @JsonIgnore public void addSort(String field, String operator) { if (this.sort == null) { this.sort = new String[1]; this.sort[0] = operator + field; } else { boolean find = false; for (int i = 0; i < this.sort.length; i++) { String f = this.sort[i]; if (field.equals(f.substring(1, f.length()))) { this.sort[i] = operator + field; find = true; break; } } if (!find) { String[] array = Arrays.copyOf(this.sort, this.sort.length + 1); array[this.sort.length] = operator + field; this.sort = array; } } } SearchModel(); String getQ(); void setQ(String q); Integer getOffset(); void setOffset(Integer offset); Integer getLimit(); void setLimit(Integer limit); String[] getFields(); void setFields(String[] fields); String[] getSort(); void setSort(String[] sort); String[][] getFilter(); void setFilter(String[][] filter); void setFilterExpression(String filter); long getTotalCount(); void setTotalCount(long totalCount); HttpServletResponse getResponse(); void setResponse(HttpServletResponse response); @JsonIgnore void addFilter(String field, String operator, String value); @JsonIgnore void addSort(String field, String operator); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void addSort() { SearchModel model = new SearchModel(); model.addSort("field", "-"); assertArrayEquals(new String[]{"-field"}, model.getSort()); model.addSort("field1", "+"); assertArrayEquals(new String[]{"-field", "+field1"}, model.getSort()); model.addSort("field", "+"); assertArrayEquals(new String[]{"+field", "+field1"}, model.getSort()); }