@Test public void shouldDecodeShorterRepeatingGroupsAfterReset() throws Exception { final Decoder decoder = decodeHeartbeat(REPEATING_GROUP_MESSAGE); assertValidRepeatingGroupDecoded(decoder); decoder.reset(); decode(SINGLE_REPEATING_GROUP_MESSAGE, decoder); assertSingleRepeatingGroupDecoded(decoder); }
@Test public void shouldResetDifferentFieldTypes() throws Exception { final Decoder decoder = (Decoder)fieldsMessage.getConstructor().newInstance(); decode(EG_FIELDS_MESSAGE, decoder); decoder.reset(); assertRequiredFieldsMessageFieldsAsStringDecoded(decoder, "", "", ""); assertOptionalDifferentFieldsNotDecoded(decoder); decode(EG_NO_OPTIONAL_FIELDS_MESSAGE, decoder); assertRequiredFieldsMessageFieldsDecoded(decoder, "USD", "N", "US"); assertOptionalDifferentFieldsNotDecoded(decoder); assertValid(decoder); }
@Test public void shouldDecodeRepeatingGroupsAfterResetWithoutValidation() throws Exception { final Decoder decoder = decodeHeartbeatWithoutValidation(REPEATING_GROUP_MESSAGE); assertValidRepeatingGroupDecoded(decoder); decoder.reset(); decode(REPEATING_GROUP_MESSAGE, decoder); assertValidRepeatingGroupDecoded(decoder); }
@Test public void shouldDecodeRepeatingGroupsAfterReset() throws Exception { final Decoder decoder = decodeHeartbeat(REPEATING_GROUP_MESSAGE); assertValidRepeatingGroupDecoded(decoder); decoder.reset(); decode(REPEATING_GROUP_MESSAGE, decoder); assertValidRepeatingGroupDecoded(decoder); }
@Test public void shouldNotRetainIntEnumFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals(10, getMethod(decoder, INT_ENUM_RF)); assertEquals("TEN", getMethod(decoder, INT_ENUM_RF + "AsEnum").toString()); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals(MISSING_INT, getMethod(decoder, INT_ENUM_RF)); assertEquals(UNKNOWN_NAME, getMethod(decoder, INT_ENUM_RF + "AsEnum").toString()); }
@Test public void shouldNotRetainStringEnumFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals("one", getMethod(decoder, STRING_ENUM_RF + "AsString")); assertEquals("ONE", getMethod(decoder, STRING_ENUM_RF + "AsEnum").toString()); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals("", getMethod(decoder, STRING_ENUM_RF + "AsString")); assertEquals(UNKNOWN_NAME, getMethod(decoder, STRING_ENUM_RF + "AsEnum").toString()); }
@Test public void shouldNotRetainCharEnumFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals('b', getMethod(decoder, CHAR_ENUM_RF)); assertEquals("BANANA", getMethod(decoder, CHAR_ENUM_RF + "AsEnum").toString()); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals(MISSING_CHAR, getMethod(decoder, CHAR_ENUM_RF)); assertEquals(UNKNOWN_NAME, getMethod(decoder, CHAR_ENUM_RF + "AsEnum").toString()); }
@Test public void shouldResetTheInvalidAccessors() throws Exception { final Decoder decoder = decodeHeartbeat(TAG_APPEARS_MORE_THAN_ONCE_MESSAGE); decoder.validate(); decoder.reset(); assertEquals("Failed to reset tag id", NO_ERROR, decoder.invalidTagId()); assertEquals("Failed to reset reject reason", NO_ERROR, decoder.rejectReason()); }
@Test public void shouldNotRetainStringFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals("one", getMethod(decoder, STRING_RF + "AsString")); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals("", getMethod(decoder, STRING_RF + "AsString")); }
@Test public void shouldNotRetainIntegerFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals(10, getMethod(decoder, INT_RF)); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals(Integer.MIN_VALUE, getMethod(decoder, INT_RF)); }
@Test public void shouldNotRetainCharFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals('b', getMethod(decoder, CHAR_RF)); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals('\u0001', getMethod(decoder, CHAR_RF)); }
@Test public void shouldLeaveDecoderInUsableIfValidationFailsDuringRepeatingGroup() throws Exception { //Given final Decoder decoder = decodeHeartbeat(FIELD_DEFINED_TWICE_IN_MESSAGE); //When assertFalse("Failed validation when it should have passed", decoder.validate()); assertEquals("Wrong reject reason", TAG_APPEARS_MORE_THAN_ONCE, decoder.rejectReason()); //Then decoder.reset(); decode(NO_MISSING_REQUIRED_FIELDS_IN_REPEATING_GROUP_MESSAGE, decoder); assertTrue("Failed validation when it should have passed", decoder.validate()); }
@Test public void shouldNotRetainDecimalFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable { final Decoder decoder = createRequiredFieldMessageDecoder(); decode(RF_ALL_FIELDS, decoder); assertEquals(new DecimalFloat(123456, 3), getMethod(decoder, DECIMAL_RF)); decoder.reset(); decode(RF_NO_FIELDS, decoder); assertEquals(DecimalFloat.MISSING_FLOAT, getMethod(decoder, DECIMAL_RF)); assertEquals(DecimalFloat.ZERO, getMethod(decoder, DECIMAL_RF)); }
@Test public void shouldLeaveDecoderInUsableIfUnknownFieldForRepeatingGroupReachedAndRejectingOn() throws Exception { //Given final Decoder decoder = decodeHeartbeatWithRejectingUnknownFields(REPEATING_GROUP_WITH_UNKNOWN_FIELD); //When assertFalse("Passed validation with missing fields", decoder.validate()); assertEquals("Wrong tag id", 1000, decoder.invalidTagId()); assertEquals("Wrong reject reason", INVALID_TAG_NUMBER, decoder.rejectReason()); //Then decoder.reset(); decode(NO_MISSING_REQUIRED_FIELDS_IN_REPEATING_GROUP_MESSAGE, decoder); assertTrue("Failed validation when it should have passed", decoder.validate()); }
@Test public void shouldResetFields() throws Exception { final Decoder decoder = decodeHeartbeat(ENCODED_MESSAGE); decoder.reset(); assertFalse(hasTestReqId(decoder)); assertFalse(hasBooleanField(decoder)); assertFalse(hasDataField(decoder)); assertFalse(hasComponentField(decoder)); assertFalse(hasNoEgGroupGroupCounter(decoder)); assertEquals(MISSING_FLOAT, getFloatField(decoder)); assertEquals(MISSING_INT, getIntField(decoder)); }
@Test public void shouldResetAllRepeatingGroupEntries() throws Exception { final Decoder decoder = decodeHeartbeat(MULTIPLE_ENTRY_REPEATING_GROUP); Object group = get(decoder, "secondEgGroupGroup"); assertEquals("TOM", get(group, "secondGroupFieldAsString")); group = next(group); assertEquals("ANDREY", get(group, "secondGroupFieldAsString")); decoder.reset(); decode(MULTIPLE_ENTRY_REPEATING_GROUP_WITHOUT_OPTIONAL, decoder); group = get(decoder, "secondEgGroupGroup"); assertNull(get(group, "secondGroupFieldAsString")); group = next(group); assertNull(get(group, "secondGroupFieldAsString")); }
@Test public void shouldResetAllNestedRepeatingGroupEntries() throws Exception { final Decoder decoder = decodeHeartbeat(MULTI_ENTRY_NESTED_GROUP_MESSAGE); assertEquals(2, getNoEgGroupGroupCounter(decoder)); Object group = getEgGroup(decoder); assertNestedRepeating(group, 1, 1, 2); group = next(group); assertNestedRepeating(group, 2, 3, 4); decoder.reset(); decode(MULTI_ENTRY_NESTED_GROUP_MESSAGE_WITHOUT_NESTED_FIELDS, decoder); assertEquals(2, getNoEgGroupGroupCounter(decoder)); group = getEgGroup(decoder); assertNestedRepeating(group, 1, CodecUtil.MISSING_INT, CodecUtil.MISSING_INT); group = next(group); assertNestedRepeating(group, 2, CodecUtil.MISSING_INT, CodecUtil.MISSING_INT); }