Trace { public static Trace fromString(String logcatTrace) throws IllegalTraceException { if (logcatTrace == null || logcatTrace.length() < MIN_TRACE_SIZE || logcatTrace.charAt(20) != TRACE_LEVEL_SEPARATOR) { throw new IllegalTraceException( "You are trying to create a Trace object from a invalid String. Your trace have to be " + "something like: '02-07 17:45:33.014 D/Any debug trace'."); } TraceLevel level = TraceLevel.getTraceLevel(logcatTrace.charAt(TRACE_LEVEL_INDEX)); String date = logcatTrace.substring(0, END_OF_DATE_INDEX); String message = logcatTrace.substring(START_OF_MESSAGE_INDEX, logcatTrace.length()); return new Trace(level, date + " " + message); } Trace(TraceLevel level, String message); static Trace fromString(String logcatTrace); TraceLevel getLevel(); String getMessage(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final int MIN_TRACE_SIZE; static final int TRACE_LEVEL_INDEX; }
@Test(expected = IllegalTraceException.class) public void shouldThrowExceptionIfTraceInputIsNull() throws IllegalTraceException { Trace.fromString(null); }
@Test(expected = IllegalTraceException.class) public void shouldThrowExceptionIfTraceHasNoLevel() throws IllegalTraceException { Trace.fromString("Any trace without trace level indicated"); }
@Test(expected = IllegalTraceException.class) public void shouldThrowExceptionIfTraceCointaisJustLevel() throws IllegalTraceException { Trace.fromString("D"); }
@Test(expected = IllegalTraceException.class) public void shouldThrowExceptionIfTraceHasNotTraceLevelSeparator() throws IllegalTraceException { Trace.fromString("D Any trace message"); }